Skip to main content

Module request

Module request 

Source
Expand description

Requests a world answers, and the waiting for their answers. Requests a world answers, and the waiting for their answers.

A job is one way: what one world says to another is a closure, and nothing comes back with it. A caller that needs a value the other world makes asks for it, and Pending is the asking: it sends the job, names what it asked for with a key of the caller’s own — a ball’s entity, say — and folds whatever came back into the world on the caller’s own tick.

Three things make it more than a queue of answers:

  • An answer is named. Two requests are not told apart by the payload they carry: the key the caller asked with is the key the answer comes back under, so a ball finds its own instance however many others were asked for at the same time.
  • The wait is bounded. A request whose answer has not come within timeout seconds is given up on, and so is every request still outstanding when the world that owes them ends: a job a panic took with it never answers, and neither does a world that stopped.
  • Nothing waits on an empty slot. The answers are folded on the caller’s tick, so a caller never blocks, and an answer that arrives for a request already given up on is dropped instead of delivered twice.

A Pending is not a future and the wait is not a wakeup: an answer lands in a queue, and the tick that needs it folds it. That is what keeps a stepped world’s wait identical to a threaded one’s, and what lets an answer be applied straight to the world rather than handed to a continuation outside it — a continuation could not hold the &mut World the answer is for, and would have to wait for the tick anyway.

Re-exports§

use async_channel::Receiver; 🔒
use async_channel::Sender; 🔒
use async_channel::unbounded; 🔒
use unlit_ecs::World; 🔒
use crate::channel::SnapshotReader; 🔒
use crate::job::JobSender; 🔒
use crate::job::SendError; 🔒
use crate::thread::WorldState; 🔒

Structs§

Pending
The requests one world owes a caller, and the answers that have come back.

Enums§

Settled
How one request ended.

Functions§

ended 🔒
Whether the world behind a reader of its state has ended.