Perform async work synchronously in Node.js using a separate process with first-class TypeScript support
# yarn
yarn add synckit
# npm
npm i synckit
// runner.js
import { createSyncFn } from 'synckit'
// the worker path must be absolute
const syncFn = createSyncFn(require.resolve('./worker'))
// do whatever you want, you will get the result synchronously!
const result = syncFn(...args)
// worker.js
import { runAsWorker } from 'synckit'
runAsWorker(async (...args) => {
// do expensive work
// but you must make sure the `result` is serializable by `JSON.stringify`
return result
})
Detailed changes for each release are documented in CHANGELOG.md.