Skip to main content

DEDUP_CANCELLED_SENTINEL

Constant DEDUP_CANCELLED_SENTINEL 

Source
pub const DEDUP_CANCELLED_SENTINEL: &str = "\x00CANCELLED";
Expand description

ยงBehavior on Drop

When a DeduplicationToken is dropped without calling complete(), the following sequence occurs:

  1. Cancellation signal: The Drop impl sends a sentinel cancellation string ("\x00CANCELLED") over the broadcast channel before removing the entry. Any tasks already blocked in wait_for_result() receive this value via rx.recv() and return Some("\x00CANCELLED") rather than None. Callers of wait_for_result that inspect the returned string can detect cancellation by checking for this sentinel.

  2. Entry removal: After the cancellation broadcast the InProgress entry is removed from the shared map. This drops the Sender, closing the broadcast channel. Any tasks that subscribe after the removal will find no entry and wait_for_result will return None.

  3. Re-registrability: Because the entry is removed, the next caller to invoke check_and_register for the same key will receive a fresh New token and can retry processing.

Waiters are NOT left hanging indefinitely. They either receive the cancellation sentinel or None (if they race with the removal), both of which are finite outcomes that unblock the awaiting task promptly.

The sentinel value "\x00CANCELLED" uses a NUL prefix which cannot appear in normal LLM output, making it safe to use as a reserved signal.