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
Conversation
…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>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
Two edits in one paragraph of
guide/EFFECTS.md, "The JS side":Why
0with anabsolute
io_tick()deadline", since Fix stale C helper calls in the effects guide #947). The JS side showed onlyio_park_on(fd, out, k, more). The JS runtime'sio_park_onhas takena fifth argument,
at, since TCP.poll (TCP.poll is a receive with a deadline: a park waits on its fd and its clock, whichever fires first (#858) #861), andtcp_poll.jsusesit. It is an absolute
performance.now()time in ms:io_waitturns itinto
select's timeout and compares it withperformance.now(). If youleave it out, the park waits on
fdalone. The argument appears only inthe runtime source inside
comp.ts, and no Base signature shows it. Sosomeone writing a JS twin of a timed C effect cannot find it.
io_sys()has had nopollsince the JS loop moved toselectinA read parked on a FIFO sees its end on macOS: the IO loop waits with select (#928) #932.
io_sys().pollisundefined, andselectis the call it binds.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), andmorereports how long the park lasted. Its C twin parks withio_wait_on(w, fd, POLLIN, io_tick() + 50 ms, more). Over four runs:bend main.bend-o x.js && bun x.js-o x && ./xOn 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().pollis"undefined"andtypeof io_sys().selectis"function", on both JS lanes.bun gates/repo.ts: 46 / 46. The guide is 1592 ttok, under its cap of1600.
No test is added because the change is to the guide only.
tests/io/tcp_poll.bendalready exercises the JS deadline throughTCP.poll.