spawn-generator
v0.0.1
Published
Write the synchronous-like code with promises and generators.
Downloads
7
Readme
spawn-generator
Write the synchronous-like code with promises and generators
Example
let spawnGenerator = require('spawn-generator');
let generatorFunction = function*(fruit) {
let fruits = [];
fruits.push(yield asyncMethod('apple')); // asyncMethod returns Promise
fruits.push(yield asyncMethod(fruit));
return fruits;
};
let functionToCall = spawnGenerator(generatorFunction);
functionToCall('banana')
.then(
(fruits) => console.log(fruits) // outputs ['apple', 'banana']
);
spawnGenerator(generatorFunction, 'orange')
.then(
(fruits) => console.log(fruits) // outputs ['apple', 'orange']
);