Skip to content

createMemoryChannel

createMemoryChannel(): [Channel, Channel]

Defined in: packages/runtime/src/container/proxy.ts:91

Build an in-memory Channel pair for testing.

[Channel, Channel]

A tuple [a, b] where messages posted on a arrive on b.onmessage, and vice versa.

Uses structuredClone for realistic serialization (catches non-cloneable payloads the same way a real MessagePort would) and queueMicrotask for async delivery that mirrors MessagePort timing.

import { createMemoryChannel, exportFS, importFS } from '@fishnet/runtime/container/proxy'
import { memoryFS } from '@fishnet/core'
const [srvCh, cliCh] = createMemoryChannel()
const handle = exportFS(memoryFS(), srvCh)
const proxy = importFS(cliCh)
// proxy.read / proxy.write now round-trip to the server over cloned messages
proxy.disconnect()
handle.dispose()