MCPcopy Index your code
hub / github.com/Effect-TS/effect / setup

Function setup

packages/platform-node/src/internal/worker.ts:12–47  ·  view source on GitHub ↗
({ scope, worker })

Source from the content-addressed store, hash-verified

10
11const 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)

Callers

nothing calls this directly

Calls 6

unsafeDoneMethod · 0.80
syncMethod · 0.80
makeMethod · 0.65
addFinalizerMethod · 0.65
pipeMethod · 0.65
awaitMethod · 0.45

Tested by

no test coverage detected