(sigil async)
Cooperative Async Runtime
Provides a cooperative multitasking runtime with lightweight tasks, async I/O, and timer support. Tasks yield control explicitly via blocking operations (sleep, I/O waits, channel operations).
Basic Usage
(import (sigil async))
(with-async
(go (begin
(display "Task A\n")
(sleep 0.1)
(display "Task A done\n")))
(go (begin
(display "Task B\n")
(sleep 0.05)
(display "Task B done\n"))))I/O Integration
(with-async
(go (begin
(await-readable sock)
(display (socket-read sock)))))Exports
await-readableprocedureWait until a socket is readable.
Yields to the scheduler until the socket has data available.
await-writableprocedureWait until a socket is writable.
Yields to the scheduler until the socket can accept data.
await-readable-anyvariableWait until ANY socket in a list is readable, or a timeout passes.
Registers ONE waiter for the whole list and resumes exactly once — when some socket becomes readable or (with timeout-ms:) when the deadline passes. The caller re-checks actual readiness itself (e.g. with a 0ms socket-select); a timeout resume is indistinguishable from a readable resume by design, which suits periodic-sweep uses (connection timeout reaping).
This is the cooperative alternative to looping a short-timeout native socket-select over a socket set: a busy loop like that stays perpetually runnable, and since the scheduler only polls socket io-waiters when the run-queue is empty, it starves every other task's socket I/O. Suspending on the whole set folds these sockets into the scheduler's own select instead.
A socket that is closed LOCALLY while awaited never reports readable (its fd is excluded from the poll — unlike a peer close, which surfaces as readable EOF), so waits over sockets another task may close should always pass timeout-ms: to stay bounded.
(await-readable-any (cons listen-sock client-socks) timeout-ms: 1000)await-readable-fdprocedureWait until a file descriptor is readable.
Yields to the scheduler until the fd has data available. Use for non-blocking reads from process pipes.
await-writable-fdprocedureWait until a file descriptor is writable.
Yields to the scheduler until the fd can accept data. Use for non-blocking writes to process pipes.
await-readable-fdsvariableWait until ANY of the given raw file descriptors is readable, or until an optional timeout elapses. Returns when the first fd is readable or the deadline passes.
The raw-fd sibling of await-readable-any (which takes socket objects). fds is a list of integer file descriptors; timeout-ms (keyword) is a relative millisecond cap, or #f for no timeout. Resumes exactly ONCE, so it is safe to poll a whole set of fds (e.g. a GLib main context's poll fds) in one call without the multiple-wake hazard of registering a separate waiter per fd. Off the scheduler it degrades to a blocking fd-select.
current-schedulervariable(No description)
make-schedulervariable(No description)
scheduler?variable(No description)
scheduler-spawnvariable(No description)
scheduler-runvariable(No description)
with-asyncvariable(No description)
%run-asyncvariable(No description)
resume-asyncvariable(No description)
govariable(No description)
%go-spawnvariable(No description)
yieldvariable(No description)
sleepvariable(No description)
in-async-context?variable(No description)
when-asyncvariable(No description)
if-asyncvariable(No description)
await-externalvariable(No description)
scheduler-task-countvariable(No description)
scheduler-blocked-countvariable(No description)
async-prompt-tagvariable(No description)
scheduler-enqueue!variable(No description)
scheduler-dec-blocked!variable(No description)