developit / greenlet
- воскресенье, 28 января 2018 г. в 03:15:28
🦎 Move an async function into its own thread.
Move an async function into its own thread.
A simplified single-function version of workerize.
The name is somewhat of a poor choice, but it was available on npm.
npm i -S greenlet
Accepts an async function with, produces a copy of it that runs within a Web Worker.
⚠️ Caveat: the function you pass should be pure, since they get executed in an isolated scope.
greenlet(Function) -> Function
import greenlet from 'greenlet'
let get = greenlet(async url => {
let res = await fetch(url)
return await res.json()
})
console.log(await get('/foo'))