INNER CODE UNIT · TypeScript
expose
andywer/threads.js · src/worker/index.ts:160
export function expose(exposed: WorkerFunction | WorkerModule<any>) {
if (!Implementation.isWorkerRuntime()) {
throw Error("expose() called in the master thread.")
}
if (exposeCalled) {
throw Error("expose() called more than once. This is not possible. Pass an object to expose() if you want to expose multiple functions.")
}
exposeCalled = true
if (typeof exposed === "function") {
Implementation.subscribeToMasterMessages(messageData => {
if (isMasterJobRunMessage(messageData) && !messageData.method) {
runFunction(messageData.uid, exposed, messageData.args.map(deserialize))
}
})
postFunctionInitMessage()
} else if (typeof exposed === "object" && exposed) {
Implementation.subscribeToMasterMessages(messageData => {