cope.js
Idea
cope is ment as a replacement to co for environments where you can't or don't want yet to use generator functions, but it comes with a bonus of progress reporting what co won't be able to do cause of possibility of using loops inside of generator function.
Where co manages generator function that has to yield Promises and resumes function when these Promises are resolved, cope deals with sets of function that return Promises. Basically same things can be achieved with co and cope, but, of course, in different ways.
Comparison examples
Let's say (for the sake of keeping this example very simple) that getting two requires three and operation of addition is worth separating.
vanilla example
var three = Promise;three ;
co example
;
cope example
Promise three + two ;
Installation
npm install arturkulig/cope --save
Usage
cope
is packed with UMD, so can be used as CommonJS/AMD/global/ES6 module.
ES6 example
;
CommonJS
var cope = ;
Global registration
Basic example
cope //so like this we start we define a queue // this will download something from some backend response // with fetch we have to transform response to an object if it's json console // so currently we are just previewing the response // and with this will actually run the queue
You can reuse once defined queue.
;
Advanced examples
Progress reporting
Due to lib returning enhanced Promise you can do progress reporting inside a component or a store where you hold such information.
cope
..so if everything goes OK, it should output
almost done: 25%
almost done: 50%
almost done: 75%
almost done: 100%
done!
Nesting
If nesting copes you still get most precise progress result. Let's change previous example a little bit.
cope cope
..again, if everything goes OK, it should output
almost done: 25%
almost done: 50%
almost done: 100%
done!