MCPcopy Create free account
hub / github.com/Effect-TS/effect / onMessage

Function onMessage

packages/platform/browser/src/BrowserWorkerRunner.ts:65–88  ·  view source on GitHub ↗
(portId: number)

Source from the content-addressed store, hash-verified

63 }
64
65 function onMessage(portId: number) {
66 return function(event: MessageEvent) {
67 const message = event.data as WorkerRunner.PlatformMessage<I>
68 if (message[0] === 0) {
69 const result = handler(portId, message[1])
70 if (Effect.isEffect(result)) {
71 const fiber = runFork(result)
72 fiber.addObserver(onExit)
73 trackFiber(fiber)
74 }
75 } else {
76 const port = ports.get(portId)
77 if (!port) {
78 return
79 } else if (ports.size === 1) {
80 // let the last port close with the outer scope
81 return Deferred.doneUnsafe(closeLatch, Exit.void)
82 }
83 ports.delete(portId)
84 Queue.offerUnsafe(disconnects, portId)
85 Effect.runFork(Scope.close(port[1], Exit.void))
86 }
87 }
88 }
89 function onMessageError(error: MessageEvent) {
90 Deferred.doneUnsafe(
91 closeLatch,

Callers 1

handlePortFunction · 0.70

Calls 6

runForkFunction · 0.85
addObserverMethod · 0.80
offerUnsafeMethod · 0.80
getMethod · 0.65
closeMethod · 0.65
handlerFunction · 0.50

Tested by

no test coverage detected