UNPKG

rafa

Version:

Rafa.js is a Javascript framework for building concurrent applications.

48 lines (39 loc) 1.31 kB
module.exports = (assert, Rafa) => { suite("toProperty", () => { test("creates new property", () => { var stream = Rafa.stream(); var property = stream.toProperty(); stream.write(1); assert.equal(property.get(), 1); stream.write(2); assert.equal(property.get(), 2); }); test("applies back pressure to child streams", () => { var stream = Rafa.stream(); var channel = Rafa.channel(); var nested; var values = []; stream.toProperty() .flatMap(v => { values.push(v); return nested = Rafa.stream(); }) .each(v => values.push(v)); stream.enumerate(channel); // write #1 to channel should flow through to flatMap channel.write(1); assert.equal(values.length, 1); assert.equal(values[0], 1); // write #2 to channel should be dropped assert.equal(channel.write(2), 0); assert.equal(values.length, 1); assert.equal(values[0], 1); // writing a done message from flatMap // to release the back pressure nested.write(3, true); assert.equal(values.length, 2); assert.equal(values[1], 3); // channel should be open channel.write(4); assert.equal(values.length, 3); assert.equal(values[2], 4); }); }); };