Skip to main content

wait_for_take

Function wait_for_take 

Source
async fn wait_for_take<T>(
    answer: &mut JoinHandle<T>,
    stop: &mut Receiver<bool>,
    cancel: &CancelToken,
) -> TakeResolution<T>
Expand description

Wait for a submitted take’s answer or a stop decision, whichever comes first. A submit decision is a no-op (the take is already in), and ANY other stop - Some(false) from Esc, or the channel closing at teardown - fires this take’s own cancel token and abandons the wait. The abandon must end the wait rather than re-select: a closed channel answers immediately and forever, and a loop that keeps polling it busy-spins a core until the inference runs out on its own.

The select is biased to the stop arm: when the answer lands in the same poll as a queued stop, Esc wins and the answer is dropped unread. An unbiased select picks a random ready arm, which landed a cancelled take about half the time.