chtefi
2/6/2016 - 11:24 AM

Using combined generators to "simulate" observable (with Push, not Pull)

Using combined generators to "simulate" observable (with Push, not Pull)

function* add() { let i = 1; while (true) yield i++; }
function* mul(gen) { let g = gen(); while (true) yield (g.next().value * 2); }

const obs = mul(add);
console.log(obs.next(), obs.next(), obs.next()); // 2 4 6

// you ask for the `.next()` value, you don't have a handler that is automatically called.
// main difference with Observables.