spawn-generator

0.0.1 • Public • Published

spawn-generator

Write the synchronous-like code with promises and generators

Coverage Status Build Status

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']
  );

Readme

Keywords

Package Sidebar

Install

npm i spawn-generator

Weekly Downloads

2

Version

0.0.1

License

MIT

Last publish

Collaborators

  • kubajz