diff --git a/src/worker-entry.ts b/src/worker-entry.ts index 4056ade..58386ea 100644 --- a/src/worker-entry.ts +++ b/src/worker-entry.ts @@ -322,8 +322,10 @@ if (parentPort !== null && handshake?.runtimeId !== undefined) { await initRuntimeWorker(handshake, attachEndpointHandler); } -// parentPort is null when this module evaluates on the MAIN thread — user -// code importing peers.ts (e.g. a moroutine that dispatches to a peer) pulls -// this module in transitively. There is no endpoint to attach there; the -// handshake above is null on main too, so evaluation is inert by design. +// Normally this module only evaluates as a worker's entry module, where +// parentPort is set. Nothing in the library import graph pulls it in — +// peers.ts and runtime-worker receive its handler by injection, not by +// importing us — but an explicit import (e.g. from a test) can evaluate it +// on the MAIN thread, where parentPort is null and there is no endpoint to +// attach. The handshake above is null on main too, so evaluation is inert. if (parentPort !== null) attachEndpointHandler(parentPort);