-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
beb4419
commit 0fe562f
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,29 @@ | ||
# spawn-generator | ||
Write the synchronous-like code with promises and generators | ||
|
||
[![Coverage Status](https://coveralls.io/repos/github/jaroslav-kubicek/spawn-generator/badge.svg?branch=master)](https://coveralls.io/github/jaroslav-kubicek/spawn-generator?branch=master) | ||
[![Build Status](https://travis-ci.org/romadur-js/romadur.svg?branch=master)](https://travis-ci.org/romadur-js/romadur) | ||
|
||
## 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'] | ||
); | ||
``` |