Ogen
An observable Async/Await. Short for (O)bservable (Gen)erator.
Write asynchronous code that looks synchronous:
const myFunc = { const result = ; // returns promise // waits for promise and uses promise result result + ' 2'; param1; param2; param3;}Pass it into ogen() and get back an observable that lets you subscribe to all the yielded values:
const onNext = console;const onError = console;const onComplete = console; const asyncFunc = ; // Call the async function and pass params. ;// future value// future value 2// a param// another param// more params!// done.Ogen returns a full Rx Observable instance, which means you can .map(), .filter() and .skip() to your heart’s content, among other things.
Platform Notes
Obviously, this relies on generators. Works OK with Babel, Node v4+. Does not work in any IE without polyfills.
Should work in most other modern browsers.
Written for Learn JavaScript with Eric Elliott
An online course series for application developers. Ready to jump in? Learn more.
