@raminjafary/workerman
v0.1.2
Published
Run your JavaScript off the browser's main thread with inline workers
Downloads
5
Maintainers
Readme
Workerman
Run your JavaScript off the browser's main thread with inline workers
Installation
npm i @raminjafary/workerman
# or
yarn add @raminjafary/workerman
Usage
Async/Await
import Workerman from "@raminjafary/workerman";
const post = new Workerman(async function getUserPosts() {
const res = await fetch('https://jsonplaceholder.typicode.com/posts?userId=1')
return res.json()
})
;(async () => {
const data = await post.proxy()
// do sth with data
})()
Promise
import Workerman from "@raminjafary/workerman";
const post = new Workerman(id => {
return fetch(`https://jsonplaceholder.typicode.com/posts/${id}`)
.then(res => res.json())
.then(json => json)
})
post.proxy(2).then((data) => {
// do sth with data
}, console.error)