{"_id":"make-asynchronous","_rev":"4130743","name":"make-asynchronous","description":"Make a synchronous function asynchronous by running it in a worker","dist-tags":{"latest":"1.1.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2026-03-01T18:32:47.000Z","created":"2022-06-26T22:01:23.215Z","1.1.0":"2026-02-24T15:29:34.637Z","1.0.1":"2024-09-21T18:00:04.576Z","1.0.0":"2023-11-04T14:21:04.513Z","0.3.0":"2022-07-20T13:04:34.188Z","0.2.0":"2022-06-29T11:23:49.338Z","0.1.0":"2022-06-26T22:01:23.215Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/make-asynchronous.git"},"versions":{"1.1.0":{"name":"make-asynchronous","version":"1.1.0","description":"Make a synchronous function asynchronous by running it in a worker","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/make-asynchronous.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","asynchronous","async","thread","dispatch","synchronous","sync","web","worker","thread","cpu","expensive","pool"],"dependencies":{"p-event":"^6.0.0","type-fest":"^4.6.0","web-worker":"^1.5.0"},"devDependencies":{"ava":"^5.3.1","delay":"^6.0.0","in-range":"^3.0.0","time-span":"^5.1.0","tsd":"^0.29.0","xo":"^0.56.0"},"xo":{"rules":{"n/prefer-global/process":"off","n/prefer-global/buffer":"off"}},"ava":{"workerThreads":false},"gitHead":"27b024dafbae7ea67fafc04ebf5f8e483c23d04c","types":"./index.d.ts","_id":"make-asynchronous@1.1.0","bugs":{"url":"https://github.com/sindresorhus/make-asynchronous/issues"},"homepage":"https://github.com/sindresorhus/make-asynchronous#readme","_nodeVersion":"25.6.0","_npmVersion":"11.8.0","dist":{"shasum":"6225f7f1ccaab9acaac5e2fcd0b075afefff19aa","size":3607,"noattachment":false,"key":"/make-asynchronous/-/make-asynchronous-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/make-asynchronous/download/make-asynchronous-1.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/make-asynchronous_1.1.0_1771946974477_0.8898504579978774"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2026-02-24T15:29:34.637Z","publish_time":1771946974637,"_source_registry_name":"default","_cnpm_publish_time":1771946974637},"1.0.1":{"name":"make-asynchronous","version":"1.0.1","description":"Make a synchronous function asynchronous by running it in a worker","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/make-asynchronous.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","asynchronous","async","thread","dispatch","synchronous","sync","web","worker","thread","cpu","expensive","pool"],"dependencies":{"p-event":"^6.0.0","type-fest":"^4.6.0","web-worker":"1.2.0"},"devDependencies":{"ava":"^5.3.1","delay":"^6.0.0","in-range":"^3.0.0","time-span":"^5.1.0","tsd":"^0.29.0","xo":"^0.56.0"},"xo":{"rules":{"n/prefer-global/process":"off","n/prefer-global/buffer":"off"}},"ava":{"workerThreads":false},"_id":"make-asynchronous@1.0.1","gitHead":"7fce502f8c5f7d2a4af20f253e9dbb14c68fa21c","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/make-asynchronous/issues"},"homepage":"https://github.com/sindresorhus/make-asynchronous#readme","_nodeVersion":"22.6.0","_npmVersion":"10.6.0","dist":{"shasum":"5ff174bae4e4371746debff112103545037373ee","size":3636,"noattachment":false,"key":"/make-asynchronous/-/make-asynchronous-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/make-asynchronous/download/make-asynchronous-1.0.1.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/make-asynchronous_1.0.1_1726941604392_0.6486585080991079"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-09-21T18:00:04.576Z","publish_time":1726941604576,"_source_registry_name":"default","_cnpm_publish_time":1726941604576},"1.0.0":{"name":"make-asynchronous","version":"1.0.0","description":"Make a synchronous function asynchronous by running it in a worker","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/make-asynchronous.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","asynchronous","async","thread","dispatch","synchronous","sync","web","worker","thread","cpu","expensive","pool"],"dependencies":{"p-event":"^6.0.0","type-fest":"^4.6.0","web-worker":"^1.2.0"},"devDependencies":{"ava":"^5.3.1","delay":"^6.0.0","in-range":"^3.0.0","time-span":"^5.1.0","tsd":"^0.29.0","xo":"^0.56.0"},"xo":{"rules":{"n/prefer-global/process":"off","n/prefer-global/buffer":"off"}},"ava":{"workerThreads":false},"types":"./index.d.ts","gitHead":"3c69d2820238fbe2fd06084fb1327fd1478d3204","bugs":{"url":"https://github.com/sindresorhus/make-asynchronous/issues"},"homepage":"https://github.com/sindresorhus/make-asynchronous#readme","_id":"make-asynchronous@1.0.0","_nodeVersion":"18.18.2","_npmVersion":"9.2.0","dist":{"shasum":"a65f848bbdce8b9e7907530ffe303bb4da2ed30e","size":3595,"noattachment":false,"key":"/make-asynchronous/-/make-asynchronous-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/make-asynchronous/download/make-asynchronous-1.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/make-asynchronous_1.0.0_1699107664292_0.9898476917283539"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-11-04T14:21:04.513Z","publish_time":1699107664513,"_source_registry_name":"default","_cnpm_publish_time":1699107664513},"0.3.0":{"name":"make-asynchronous","version":"0.3.0","description":"Make a synchronous function asynchronous by running it in a worker","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/make-asynchronous.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","types":"./index.d.ts","engines":{"node":">=14.16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","asynchronous","async","thread","dispatch","synchronous","sync","web","worker","thread","cpu","expensive","pool"],"dependencies":{"p-event":"^5.0.1","type-fest":"^2.14.0","web-worker":"^1.2.0"},"devDependencies":{"ava":"^4.3.0","delay":"^5.0.0","in-range":"^3.0.0","time-span":"^5.1.0","tsd":"^0.21.0","xo":"^0.50.0"},"xo":{"rules":{"n/prefer-global/process":"off","n/prefer-global/buffer":"off"}},"ava":{"workerThreads":false},"gitHead":"8be62c951084a3a950bc168f6a041c3d1d962cab","bugs":{"url":"https://github.com/sindresorhus/make-asynchronous/issues"},"homepage":"https://github.com/sindresorhus/make-asynchronous#readme","_id":"make-asynchronous@0.3.0","_nodeVersion":"14.19.3","_npmVersion":"8.3.2","dist":{"shasum":"5efd81cf0fac8ffa3f7057813f7af66d5298b5ce","size":3919,"noattachment":false,"key":"/make-asynchronous/-/make-asynchronous-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/make-asynchronous/download/make-asynchronous-0.3.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/make-asynchronous_0.3.0_1658322273987_0.18548501214179502"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-07-20T13:38:05.610Z","publish_time":1658322274188,"_cnpm_publish_time":1658322274188},"0.2.0":{"name":"make-asynchronous","version":"0.2.0","description":"Make a synchronous function asynchronous by running it in a worker","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/make-asynchronous.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","types":"./index.d.ts","engines":{"node":">=14.16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","asynchronous","async","thread","dispatch","synchronous","sync","web","worker","thread","cpu","expensive","pool"],"dependencies":{"p-event":"^5.0.1","type-fest":"^2.14.0","web-worker":"^1.2.0"},"devDependencies":{"ava":"^4.3.0","delay":"^5.0.0","in-range":"^3.0.0","time-span":"^5.1.0","tsd":"^0.21.0","xo":"^0.50.0"},"xo":{"rules":{"n/prefer-global/process":"off","n/prefer-global/buffer":"off"}},"ava":{"workerThreads":false},"gitHead":"2d3fdfaa0b972876b197f12e0eb3fd0ba79bf6fb","bugs":{"url":"https://github.com/sindresorhus/make-asynchronous/issues"},"homepage":"https://github.com/sindresorhus/make-asynchronous#readme","_id":"make-asynchronous@0.2.0","_nodeVersion":"14.19.3","_npmVersion":"8.3.2","dist":{"shasum":"c415fd843510ff9910e99dc0ad34949235ed67e7","size":3146,"noattachment":false,"key":"/make-asynchronous/-/make-asynchronous-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/make-asynchronous/download/make-asynchronous-0.2.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/make-asynchronous_0.2.0_1656501829164_0.672718935531931"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-06-29T12:54:04.860Z","publish_time":1656501829338,"_cnpm_publish_time":1656501829338},"0.1.0":{"name":"make-asynchronous","version":"0.1.0","description":"Make a synchronous function asynchronous by running it in a worker","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/make-asynchronous.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","types":"./index.d.ts","engines":{"node":">=14.16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","asynchronous","async","thread","dispatch","synchronous","sync","web","worker","thread","cpu","expensive","pool"],"dependencies":{"type-fest":"^2.14.0","web-worker":"^1.2.0"},"devDependencies":{"ava":"^4.3.0","delay":"^5.0.0","in-range":"^3.0.0","time-span":"^5.1.0","tsd":"^0.21.0","xo":"^0.50.0"},"xo":{"rules":{"n/prefer-global/process":"off","n/prefer-global/buffer":"off"}},"ava":{"workerThreads":false},"gitHead":"de08673909684404ebe3f582add17a0e81c9b13f","bugs":{"url":"https://github.com/sindresorhus/make-asynchronous/issues"},"homepage":"https://github.com/sindresorhus/make-asynchronous#readme","_id":"make-asynchronous@0.1.0","_nodeVersion":"14.19.3","_npmVersion":"8.3.2","dist":{"shasum":"77a1e5579b99cd8ca5fc848f3a5d6bfdc242df17","size":2681,"noattachment":false,"key":"/make-asynchronous/-/make-asynchronous-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/make-asynchronous/download/make-asynchronous-0.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/make-asynchronous_0.1.0_1656280883037_0.5019612294164111"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-06-26T22:01:25.231Z","publish_time":1656280883215,"_cnpm_publish_time":1656280883215}},"readme":"# make-asynchronous\n\n> Make a synchronous function asynchronous by running it in a [worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)\n\nThis makes it super simple to offload some expensive work without having to deal with the complex Web Workers API.\n\n**Please upvote [this Node.js issue](https://github.com/nodejs/node/issues/43583) ????** It would let us reduce the amount of dependencies and simplify the code.\n\n*Works in Node.js and browsers.*\n\n## Install\n\n```sh\nnpm install make-asynchronous\n```\n\n## Usage\n\n```js\nimport makeAsynchronous from 'make-asynchronous';\n\nconst fn = makeAsynchronous(number => {\n\treturn performExpensiveOperation(number);\n});\n\nconsole.log(await fn(2));\n//=> 345342\n```\n\n## API\n\n### makeAsynchronous(function)\n\nReturns a wrapped version of the given function which executes asynchronously in a background thread (meaning it will not block the main thread).\n\nThe given function is serialized, so you cannot use any variables or imports from outside the function scope. You can instead pass in arguments to the function.\n\n### makeAsynchronousIterable(function)\n\nMake the iterable returned by a function asynchronous by running it in a worker.\n\n```js\nimport {makeAsynchronousIterable} from 'make-asynchronous';\n\nconst fn = makeAsynchronousIterable(function * (number) {\n\tyield * performExpensiveOperation(number);\n});\n\nfor await (const number of fn(2)) {\n\tconsole.log(number);\n}\n```\n\n#### fn.withSignal(signal)\n\nThe function returned by `makeAsynchronous` and `makeAsynchronousIterable` has an additional method which allows an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to be provided.\n\n```js\nimport makeAsynchronous from 'make-asynchronous';\n\nconst fn = makeAsynchronous(number => {\n\treturn performExpensiveOperation(number);\n});\n\nconst controller = new AbortController();\nconst timeoutId = setTimeout(() => {\n\tcontroller.abort();\n}, 1000); // 1 second timeout\n\nconst result = await fn.withSignal(controller.signal)(2);\nclearTimeout(timeoutId);\n\nconsole.log(result);\n//=> 345342\n```\n\n## Related\n\n- [make-synchronous](https://github.com/sindresorhus/make-synchronous) - Make an asynchronous function synchronous\n- [sleep-synchronously](https://github.com/sindresorhus/sleep-synchronously) - Block the main thread for a given amount of time\n","_attachments":{},"homepage":"https://github.com/sindresorhus/make-asynchronous#readme","bugs":{"url":"https://github.com/sindresorhus/make-asynchronous/issues"},"license":"MIT"}