[feat] comlink endpoint adapter
loynoir opened this issue · 2 comments
loynoir commented
Usage
const dohMathSync = api.doMathAsync.bind(api)
main.mjs
import { Worker } from 'worker_threads'
import * as Comlink from 'comlink'
import { Endpoint } from 'synckit'
const worker = new Worker(new URL('./worker.mjs', import.meta.url))
const api = Comlink.wrap(Endpoint(worker))
const dohMathSync = api.doMathAsync.bind(api)
worker.mjs
import { parentPort } from 'worker_threads'
import * as Comlink from 'comlink'
import { Endpoint } from 'synckit'
const api = {
async doMathAsync() {
return 4
}
}
Comlink.expose(api, Endpoint(parentPort))
Related
JounQin commented
No idea what's your meaning, please describe it in details.