Janet 1.13.1-392d5d5 Documentation
(Other Versions:
1.12.2
1.11.1
1.10.1
1.9.1
1.8.1
1.7.0
1.6.0
1.5.1
1.5.0
1.4.0
1.3.1
)
Event Module
Functions related to evented (asynchrnous) IO and a fiber based event loop.
Index
ev/call ev/cancel ev/capacity ev/chan ev/chunk ev/close ev/count ev/deadline ev/full ev/give ev/go ev/read ev/rselect ev/select ev/sleep ev/spawn ev/take ev/with-deadline ev/write
ev/call cfunction
(ev/call fn & args) Call a function asynchronously. Returns a fiber that is scheduled to run the function.Community Examples
ev/cancel cfunction
(ev/cancel fiber err) Cancel a suspended fiber in the event loop. Differs from cancel in that it returns the canceled fiber immediatelyCommunity Examples
ev/capacity cfunction
(ev/capacity channel) Get the number of items a channel will store before blocking writers.Community Examples
ev/chan cfunction
(ev/chan &opt capacity) Create a new channel. capacity is the number of values to queue before blocking writers, defaults to 0 if not provided. Returns a new channel.Community Examples
ev/chunk cfunction
(ev/chunk stream n &opt buffer timeout) Same as ev/read, but will not return early if less than n bytes are available. If an end of stream is reached, will also return early with the collected bytes.Community Examples
ev/close cfunction
(ev/close stream) Close a stream. This should be the same as calling (:close stream) for all streams.Community Examples
ev/count cfunction
(ev/count channel) Get the number of items currently waiting in a channel.Community Examples
ev/deadline cfunction
(ev/deadline sec &opt tocancel tocheck) Set a deadline for a fiber `tocheck`. If `tocheck` is not finished after `sec` seconds, `tocancel` will be canceled as with `ev/cancel`. If `tocancel` and `tocheck` are not given, they default to `(fiber/root)` and `(fiber/current)` respectively. Returns `tocancel`.Community Examples
ev/give cfunction
(ev/give channel value) Write a value to a channel, suspending the current fiber if the channel is full.Community Examples
ev/go cfunction
(ev/go fiber &opt value) Put a fiber on the event loop to be resumed later. Optionally pass a value to resume with, otherwise resumes with nil.Community Examples
ev/read cfunction
(ev/read stream n &opt buffer timeout) Read up to n bytes into a buffer asynchronously from a stream. Optionally provide a buffer to write into as well as a timeout in seconds after which to cancel the operation and raise an error. Returns the buffer if the read was successful or nil if end-of-stream reached. Will raise an error if there are problems with the IO operation.Community Examples
ev/rselect cfunction
(ev/rselect & clauses) Similar to ev/choice, but will try clauses in a random order for fairness.Community Examples
ev/select cfunction
(ev/select & clauses) Block until the first of several channel operations occur. Returns a tuple of the form [:give chan] or [:take chan x], where a :give tuple is the result of a write and :take tuple is the result of a write. Each clause must be either a channel (for a channel take operation) or a tuple [channel x] for a channel give operation. Operations are tried in order, such that the first clauses will take precedence over later clauses.Community Examples
ev/sleep cfunction
(ev/sleep sec) Suspend the current fiber for sec seconds without blocking the event loop.Community Examples
ev/spawn macro source
(ev/spawn & body) Run some code in a new fiber. This is shorthand for (ev/call (fn [] ;body)).Community Examples
ev/take cfunction
(ev/take channel) Read from a channel, suspending the current fiber if no value is available.Community Examples
ev/with-deadline macro source
(ev/with-deadline deadline & body) Run a body of code with a deadline, such that if the code does not complete before the deadline is up, it will be canceled.Community Examples
ev/write cfunction
(ev/write stream data &opt timeout) Write data to a stream, suspending the current fiber until the write completes. Takes an optional timeout in seconds, after which will return nil. Returns nil, or raises an error if the write failed.Community Examples