({ scope, worker })
| 10 | |
| 11 | const platformWorkerImpl = Worker.makePlatform<WorkerThreads.Worker | ChildProcess.ChildProcess>()({ |
| 12 | setup({ scope, worker }) { |
| 13 | return Effect.flatMap(Deferred.make<void, WorkerError>(), (exitDeferred) => { |
| 14 | const thing = "postMessage" in worker ? |
| 15 | { |
| 16 | postMessage(msg: any, t?: any) { |
| 17 | worker.postMessage(msg, t) |
| 18 | }, |
| 19 | kill: () => worker.terminate(), |
| 20 | worker |
| 21 | } : |
| 22 | { |
| 23 | postMessage(msg: any, _?: any) { |
| 24 | worker.send(msg) |
| 25 | }, |
| 26 | kill: () => worker.kill("SIGKILL"), |
| 27 | worker |
| 28 | } |
| 29 | worker.on("exit", () => { |
| 30 | Deferred.unsafeDone(exitDeferred, Exit.void) |
| 31 | }) |
| 32 | return Effect.as( |
| 33 | Scope.addFinalizer( |
| 34 | scope, |
| 35 | Effect.suspend(() => { |
| 36 | thing.postMessage([1]) |
| 37 | return Deferred.await(exitDeferred) |
| 38 | }).pipe( |
| 39 | Effect.interruptible, |
| 40 | Effect.timeout(5000), |
| 41 | Effect.catchAllCause(() => Effect.sync(() => thing.kill())) |
| 42 | ) |
| 43 | ), |
| 44 | thing |
| 45 | ) |
| 46 | }) |
| 47 | }, |
| 48 | listen({ deferred, emit, port }) { |
| 49 | port.worker.on("message", (message) => { |
| 50 | emit(message) |
nothing calls this directly
no test coverage detected