This module mainly to support three kinds of different purpose of usage:
Make asynchronous functions in an existing module into synchronized
import makeSynchronized from 'make-synchronized'const synchronized = makeSynchronized( new URL('./my-asynchronous-function-module.js', import.meta.url),)
Make a module that turns asynchronous function into synchronized
import makeSynchronized from 'make-synchronized'export default makeSynchronized(import.meta, myAsynchronousFunction)
Make an inline asynchronous function into synchronized
import makeSynchronized from 'make-synchronized'const synchronized = makeSynchronized(() => Promise.resolve('foo'))
Named exports
import { makeSynchronized, // Same as the default export makeDefaultExportSynchronized, makeModuleSynchronized, makeSynchronizedFunction, makeSynchronizedFunctions, makeInlineFunctionSynchronized,} from 'make-synchronized'
The given function is executed in a separate environment, so you cannot use any variables/imports from outside the scope of the function. You can pass in arguments to the function. To import dependencies, use await import(…) in the function body.
Explicit version of makeSynchronized(module, implementation) that only returns Proxy with synchronized functions for export.
import {makeSynchronizedFunctions} from 'make-synchronized'export const { // MUST match the key in second argument foo, bar,} = makeSynchronizedFunctions(import.meta, { foo: async () => 'foo export called', bar: async () => 'bar export called',})
Make an existing module's default export to be a synchronized function.
Explicit version of makeSynchronized(module) that only returns the synchronized default export.
import {makeDefaultExportSynchronized} from 'make-synchronized'const foo = makeModuleSynchronized('foo')foo()// -> default export of `foo` module is called.
import {makeModuleSynchronized} from 'make-synchronized'const {default: foo, bar} = makeModuleSynchronized('foo')foo()// -> default export of `foo` module is called.bar()// -> `bar` function from `foo` module is called.
makeInlineFunctionSynchronized(implementOrCode: function | string)
Make an inline asynchronous function into synchronized.
[!IMPORTANT]
The given function is executed in a separate environment, so you cannot use any variables/imports from outside the scope of the function. You can pass in arguments to the function. To import dependencies, use await import(…) in the function body.