Skip to content
A WebWorker extension that takes a function as argument
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Add LICENSE Sep 12, 2017 Update readme Sep 12, 2017
index.html Update demo Sep 12, 2017
package.json Initial commit Sep 12, 2017


ClosureWorker is a small extension of WebWorker that allows you to define a worker function inline instead of as a separate url.

It works by "compiling" the passed function, and injecting variables. This get's turned into a Blob and then a Object URL which can be passed to a native WebWorker.

Tested on latest version of Google Chrome and Safari.

Live demo


yarn add closure-worker
npm install closure-worker


const blocking = (n) => {
    let sum = 0
    for (let i = 0; i < n; i++) {
        sum += Math.pow(Math.random() * Math.PI, 2)
    // return sum

const handler = (msg) => {
    console.log(`Worker completed, result: ${}`)

let worker = new ClosureWorker(blocking, handler, { n: 1000000 })
You can’t perform that action at this time.