Minimalistic, zero dependency, async utilities for ES6, ES2015, node v6. This library assume node v6 or above with ES2015 Promise and generators. It has no dependency.
DEPRECATED: Use native async/await from Node.js >8.x. This was just a stop gap plugin, but now, no good reason to use it unless you have to ben on node.js 6.x.
Promisify
Promisify a function which follow the standard callback(err, result) pattern.
const promisify = promisify; const glob = ;const pglob = ; // the call back way // the promise way;
- Use the default Node v6, es2015 Promise.
- Does not use
bind()
as there are some performance issues.
run
Run a generator function or generator function "instance" (after first call) that supports direct value, promise in yields, and return a ES2015 Promise which result with the return of the generator function.
const run = run; { val = val || 0; var a = 12; var b = ; var c = ; // can be any promise that have a then function. return a + b + c;}// assuming getB() return 8, and getPromiseForC() will resolve to 10. ; // 30 ; // 40
Combining promise, yield, generator
const async6 = ;const promisify = async6promisify;const run = async6run; const pglob = ; // using generators, promise, and async6.run (see below){ root = root || "" var jsFiles = ; var cssFiles = ; return jsFiles cssFiles;} ;// or;