Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] comlink endpoint adapter #139

Closed
loynoir opened this issue Aug 25, 2023 · 2 comments
Closed

[feat] comlink endpoint adapter #139

loynoir opened this issue Aug 25, 2023 · 2 comments

Comments

@loynoir
Copy link

loynoir commented Aug 25, 2023

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

GoogleChromeLabs/comlink#642

@JounQin
Copy link
Member

JounQin commented Aug 26, 2023

No idea what's your meaning, please describe it in details.

@loynoir
Copy link
Author

loynoir commented Sep 15, 2023

Close in favor of #140

@loynoir loynoir closed this as completed Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants