Skip to content

The effects guide gives the JS park its deadline, as it gives the C one, and names select, not poll, in io_sys() - #1050

Merged
nicolas-abril merged 1 commit into
bendlang:mainfrom
aldeni:effects-guide-js-deadline
Sep 25, 2026
Merged

nicolas-abril merged 1 commit into
bendlang:mainfrom
aldeni:effects-guide-js-deadline

Conversation

@aldeni

@aldeni aldeni commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

What changes

Two edits in one paragraph of guide/EFFECTS.md, "The JS side":

 `more()` when `fd` is ready; `more` answers the value, or `undefined` to
-park again. `io_sys()` is `libc` through `bun:ffi`
-(`read`, `recv`, `poll`, `errno`); `tcp_recv.js` shows the full shape.
+park again. Add an absolute `performance.now()` deadline as a fifth
+argument to also wake on time. `io_sys()` is `libc` through `bun:ffi`
+(`read`, `recv`, `select`, `errno`); `tcp_recv.js` shows the full shape.

Why

How it was checked

Linux x86-64, Bun 1.3.11, clang 22.1.8. I did not run it on macOS.

  • A throwaway effect opens a pipe that nobody writes. It parks on the read
    end with io_park_on(p[0], false, k, more, performance.now() + 50), and
    more reports how long the park lasted. Its C twin parks with
    io_wait_on(w, fd, POLLIN, io_tick() + 50 ms, more). Over four runs:

    lane empty pipe, 50 ms one byte, 1 s no fd, 50 ms
    bend main.bend 50.6-51.4 ms 0.0-0.1 ms 50.2-50.5 ms
    -o x.js && bun x.js 50.7-50.8 ms 0.0 ms 50.2-50.3 ms
    -o x && ./x 50.1 ms 0.0 ms 50.1 ms

    On every lane, the empty-pipe wake comes after the deadline and its read
    finds nothing.

  • Without the fifth argument, the same park on the empty pipe does not
    wake within 3 s.

  • typeof io_sys().poll is "undefined" and typeof io_sys().select is
    "function", on both JS lanes.

  • bun gates/repo.ts: 46 / 46. The guide is 1592 ttok, under its cap of
    1600.

No test is added because the change is to the guide only.
tests/io/tcp_poll.bend already exercises the JS deadline through
TCP.poll.

…ne, and names select, not poll, in io_sys()

guide/EFFECTS.md says how a C effect's park also wakes on time (an
absolute io_tick() deadline in io_wait_on, since bendlang#947), but its JS side
showed only io_park_on(fd, out, k, more). The JS runtime's io_park_on
has taken a fifth argument, at, since TCP.poll (bendlang#861): an absolute
performance.now() time in milliseconds, which io_wait turns into
select's timeout and compares with performance.now() on return; left
out, the park waits on fd alone. tcp_poll.js uses it. One sentence in
the JS side now says so, in the words of the C side's.

The same paragraph named poll among io_sys()'s calls. The JS loop has
waited with select since bendlang#932 (macOS's poll misses a FIFO's close):
io_sys().poll is undefined, and select is the call it binds.

Checked on Linux x86-64, Bun 1.3.11, with a throwaway effect:
- It opens a pipe nobody writes, parks on the read end with
  io_park_on(p[0], false, k, more, performance.now() + 50), and more
  reports the time since the park. `bend main.bend` wakes after
  50.6-51.4 ms and `bend main.bend -o x.js && bun x.js` after
  50.7-50.8 ms, past the deadline, the read finding nothing; the C
  twin, io_wait_on(w, fd, POLLIN, io_tick() + 50 ms, more), wakes
  after 50.1 ms. With a byte in the pipe and a 1 s deadline, all three
  wake at once; with no fd and only the deadline, after 50.1-50.5 ms.
- Without the fifth argument, the same park on the empty pipe does not
  wake within 3 s.
- typeof io_sys().poll is "undefined" and typeof io_sys().select
  "function", on both JS lanes.
- gates/repo.ts passes 46/46; the guide is 1592 ttok, under its 1600.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nicolas-abril
nicolas-abril merged commit 774ef64 into bendlang:main Sep 25, 2026
@Lorenzobattistela Lorenzobattistela mentioned this pull request Sep 25, 2026
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.

2 participants