seem: Promises and Generators for async/await
seem
is a tiny module that gives you the power of ES7's async/await
using ES6's yield
.
This is @ForbesLindesay's async
function from his Control Flow Utopia presentation, with an extension to accept non-thenable.
var seem = ; var g = ;
The function will now return a Promise that will resolve to the value of the return
statement upon success.
Essentially, inside a seem
-ified generator function, yield
turns its Promise argument into that Promise's result.
Replace Promise.resolve
in the example with your preferred asynchronous operation for full power.
Accepts non-Promises
If the value you yield
is not thenable, seem
will turn it into a Promise.
var seem = ; var g = ;
In other words you can freely mix-and-match Promises and non-Promises, and seem
will do the right thing.
(Contrarily to co
v4, seem
will not attempt to resolve Promises in an array or an object given to yield
. It will pass the array or object as-is.)
This module uses native Promises by default; seem.use(Promise)
to provide your own (or use a polyfill before including the module).