es6-async-pipe
Promise + Generator for async pipe.
es6-async-pipe
Understand - provide
pipe
for JavaScript butchainable
; - provide
goto
for JavaScript butcallback
; - provide
Asynchronous Programming
without Generators and Promise; - pipe functions will be run after all sync statements be done;
- allow multiple parameters to next pipe function;
Get Start
This module export as es2015-module, you need use es6 module to import es6-async-pipe
, you can npm install --save-dev webpack babel-core babel-loader babel-preset-es2015 babel-preset-stage-0 babel-runtime
.
package.js
example:
{
...
"devDependencies": {
"babel-core": "^6.7.4",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0",
"babel-runtime": "^6.6.1",
"webpack": "^1.12.14",
...
}
...
}
install and import
npm install es6-async-pipe --save-dev
import pipe from 'es6-async-pipe';
Create a pipe
let pipeA = ;let pipeB = ; // create a pipe with initial data for following functions call
Run async/sync functions one by one
this.next(...params);
{const timeout = window;}{args0a++;thisnext...args;}// just run async functions;// just run sync functions;// run async and sync functions;
Done/cancel pipe but not wait pipe take all functions
this.done();
and this.cancel(reason);
{const timeout = window;}{const timeout = window;}// done pipe but not wait pipe take all functions;// cancel pipe and throw reason;
Goto a named pipe function
this.define(name);
and this.goto(name, ...parameters);
{this;const timeout = window;}{const timeout = window;}// goto a named function;
Void function in pipe (NOT recommended)
;
.apply is great
let fns = ;fns; pipe;
API
pipe#done
Do something when pipe is done:
- if all pipe functions have been done;
- some pipe function take this.done();
;
pipe#catch
If some exceptions, then catch them.
;
pipe#before
Before pipe start.
;
pipe#after
After pipe end.
;
pipe#beforeEach
Before enter each pipe function.
;
pipe#afterEach
After quit each pipe function.
;
pipe#debug
Enable the debug and return logs.
;
Console output:
Enter pipe function
├ Time offset(ms): 1
└ Value snapshot: [{"a":0}]
Exit pipe function
├ Time offset(ms): 1122
└ Value snapshot: [{"a":1}]
Enter pipe function
├ Time offset(ms): 1122
└ Value snapshot: [{"a":2}]
Exit pipe function
├ Time offset(ms): 3701
└ Value snapshot: [{"a":3}]
Enter pipe function
├ Time offset(ms): 3702
└ Value snapshot: [{"a":4}]
Exit pipe function
├ Time offset(ms): 5330
└ Value snapshot: [{"a":5}]
Async pipe completed
├ Time offset(ms): 5331
└ Value snapshot: [{"a":5}]
TODO
pipe.add(fns)
,pipe.remove(fn)
andpipe.insert(fn, position)
?pipe.sleep()
to resolve competition of othersetTimeout
functions?- multiple pipe runtime support to resolve competition of other pipe?