Sagu
Simple Async Generator Utils
Game changer of javascript asynchronous process.
Sagu convert async callback functions to simple loop.
Sagu how change async process of javascript?
Stream api
So far
const res = await ;resbody;
With sagu
for await const chunk ok done of console;
Event
So far
const a = document;a;
With sagu
const a = document;for await const event dispose of eventa 'click' console;
Socket.IO
So far
const conn = ;conn;conn;
With sagu
for await const type event of ...
Polling
So far
// polling. { const res = await ; const json = res; ... ;};;
With sagu
// pollingfor await const ok response of const json = await response; ...
etc...
Sagu convert async callback function to simple loops.
Install
npm install sagu --save
Import
ES6
;
Node
const wait ws } = ;
Script
For rollup users
Use rollup-plugin-node-resolve
with module: true
.
For Webpack or other bundler users
Import normaly.
Environment
Sagu only works for environment which support asynchronous iterater(for-await-of).
Now only babel support that feature.
So now we support only babel transpilation.
babel config.
"babel": {
"plugins": [
[
"transform-runtime",
{
"helpers": false,
"polyfill": false,
"regenerator": true,
"moduleName": "babel-runtime"
}
]
],
"presets": [
"es2015",
"stage-3"
]
}
You must specify stage-3
presets and transform-runtime.
In detail,see
https://github.com/babel/babel/pull/3473
https://github.com/tc39/proposal-async-iteration
API
See API