MCPcopy Create free account
hub / github.com/MultithreadedJSBook/code-samples / exec

Method exec

ch6-thread-pool/rpc-worker.js:35–43  ·  view source on GitHub ↗
(method, ...args)

Source from the content-addressed store, hash-verified

33 }
34// THIS LINE SHOULD NOT APPEAR IN PRINT
35 exec(method, ...args) {
36 const id = ++this.next_command_id;
37 let resolve, reject;
38 const promise = new Promise((res, rej) => { resolve = res; reject = rej; });
39 const worker = this.getWorker(); // <1>
40 worker.in_flight_commands.set(id, { resolve, reject });
41 worker.worker.postMessage({ method, params: args, id });
42 return promise;
43 }
44// THIS LINE SHOULD NOT APPEAR IN PRINT
45 getWorker() {
46 let id;

Callers 1

main.jsFile · 0.45

Calls 1

getWorkerMethod · 0.95

Tested by

no test coverage detected