github

developit / greenlet

  • воскресенье, 28 января 2018 г. в 03:15:28
https://github.com/developit/greenlet


🦎 Move an async function into its own thread.



Greenlet

Greenlet npm travis

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.

Installation & Usage

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

Example

import greenlet from 'greenlet'

let get = greenlet(async url => {
	let res = await fetch(url)
	return await res.json()
})

console.log(await get('/foo'))

License

MIT