Skip to content

Conversation

@vigoo
Copy link
Contributor

@vigoo vigoo commented Oct 12, 2025

Adds initial node:stream support based on the wasmedge-quickjs implementation (which is based on Deno).
As part of this, had to also add nextTick into node:process.

Note that this is the best approximation of Node's event loop that I could do without forking rquickjs but it is not perfect. We may need to further tweak it in the future.

wasm-edge's event loop (which is also QuickJS based but not using rquickjs) does the following:

  • For each (Rust async future) poll of the runtime, it first "runs the event loop without IO"
  • This consists of an inner loop that runs until the tick/immediate task queue becomes empty:
    • First runs QuickJS's own pending jobs
    • Then runs the tick tasks
    • Then runs the immediate tasks
    • If there were tick/immediate tasks, repeat
  • Then it processes the "subtasks", which are async Rust futures

In wasm-rquickjs I could not add a separate nextTick queue in the middle of the event loop, so instead I am just using defer to enqueue them - this basically adds a task in the end of QuickJS's own queue. So the only difference between our and the wasmedge event loop is that QuickJS's internal microtasks' and the user-defined nextTick tasks's order is not strictly defined.

@vigoo vigoo marked this pull request as ready for review November 24, 2025 18:05
@vigoo vigoo linked an issue Nov 24, 2025 that may be closed by this pull request
@vigoo vigoo changed the title Node stream support, WIP Node stream support Nov 24, 2025
@vigoo vigoo merged commit 507b962 into main Nov 24, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support node:stream

3 participants