Skip to content

Instantly share code, notes, and snippets.

@mizchi
Last active April 30, 2020 06:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizchi/bf2735e6e31b5a4c66800c04d112effe to your computer and use it in GitHub Desktop.
Save mizchi/bf2735e6e31b5a4c66800c04d112effe to your computer and use it in GitHub Desktop.
minilink

Minilink

comlink から proxy やらなんやら抜いたもの。 気が向いたら npm に投げる

使い方

// worker thread
import {expose} from './minilink'
expose({
  async foo(args) {
    return args.v + 1;
  }
})
// main thread
import {wrap} from './minilink'
const api = wrap(new Worker('/myworker.js'));
const ret = await api.call('foo', {v:1});
console.log(ret); // => 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment