Skip to content

Latest commit

 

History

History
35 lines (23 loc) · 1000 Bytes

stream.md

File metadata and controls

35 lines (23 loc) · 1000 Bytes

Streams

Promises are not the only interface to deal with IO bounds. Streams are well-defined interfaces mainly used server side. With Vomit you can use streams as following on both server and front-end side:

vomit`<p>${fs.createReadStream(__dirname + '/lorem.txt')}</p>`

result:

<p>This is the content of the file lorem.txt</p>

Take a look at our examples server for some example of vomit server side.

The stream placeholder syntax is the same than everything else in Vomit. It opens the door to a multitude of libraries and modules out there using stream as their main interface.

Event emitter

Because streams use underneath the Event Emitter pattern, Vomit makes possible to use event emitters as placeholder and insert the values returned by data events.

var emitter = new Emitter()
vomit`<span>${emitter}</span>`

emitter.emit('data', 'hello ')
emitter.emit('data', 'world!')

result:

<span>hello world!</span>