| 248 | |
| 249 | /* Inject directly into the paused VM. Returns false if the VM isn't ready yet (no compilerExports, or no paused run) so callers can buffer. */ |
| 250 | function injectEvent(message) { |
| 251 | if (!compilerExports) return false; |
| 252 | const bytes = TE.encode(message); |
| 253 | const ptr = compilerExports.wasm_alloc(bytes.length); |
| 254 | new Uint8Array(compilerExports.memory.buffer, ptr, bytes.length).set(bytes); |
| 255 | const status = compilerExports.run_push_event(ptr, bytes.length); |
| 256 | compilerExports.wasm_free(ptr, bytes.length); |
| 257 | return status === 0; |
| 258 | } |
| 259 | |
| 260 | /* Push a string into the VM's event queue; wakes `receive()`. Buffers if the VM isn't paused on PENDING_EVENT yet, the driver loop drains the buffer at the next yield, so callers never need to know about the VM's readiness window. */ |
| 261 | export function pushEvent(message) { |