Skip to content

[Futures-Util] Add monotonic_token and waiter_queue modules#4446

Open
AhmedSoliman wants to merge 2 commits intomainfrom
pr4446
Open

[Futures-Util] Add monotonic_token and waiter_queue modules#4446
AhmedSoliman wants to merge 2 commits intomainfrom
pr4446

Conversation

@AhmedSoliman
Copy link
Contributor

@AhmedSoliman AhmedSoliman commented Feb 27, 2026

Extract two generic, reusable utilities into restate-futures-util:

monotonic_token: A lightweight mechanism for a producer to signal
completion of a prefix of sequentially issued work items. Provides
Token, TokenOwner, Tokens, and TokenListener types with
a phantom type parameter to prevent mixing tokens from different domains.
Uses atomics (Relaxed/Release/Acquire) for lock-free operation — no
RwLock or watch overhead.

waiter_queue: A priority-drainable queue (WaiterQueue<K, V>) designed
for the common case where entries arrive in key-order. Uses an adaptive
strategy: push_back for in-order inserts (O(1)), binary-search insert for
out-of-order (rare). Drain is always a simple front-pop. Includes a
Criterion benchmark comparing four strategies (naive, compact,
adaptive, sorted-insert).

Both modules include comprehensive documentation and tests. Neither
references any specific use-case — they are general-purpose building
blocks.


Stack created with Sapling. Best reviewed with ReviewStack.

@github-actions
Copy link

github-actions bot commented Feb 27, 2026

Test Results

  7 files    7 suites   5m 42s ⏱️
 49 tests  49 ✅ 0 💤 0 ❌
210 runs  210 ✅ 0 💤 0 ❌

Results for commit 7e9c487.

♻️ This comment has been updated with latest results.

Extract two generic, reusable utilities into restate-futures-util:

**monotonic_token**: A lightweight mechanism for a producer to signal
completion of a prefix of sequentially issued work items. Provides
Token<T>, TokenOwner<T>, Tokens<T>, and TokenListener<T> types with
a phantom type parameter to prevent mixing tokens from different domains.
Uses atomics (Relaxed/Release/Acquire) for lock-free operation — no
RwLock or watch overhead.

**waiter_queue**: A priority-drainable queue (WaiterQueue<K, V>) designed
for the common case where entries arrive in key-order. Uses an adaptive
strategy: push_back for in-order inserts (O(1)), binary-search insert for
out-of-order (rare). Drain is always a simple front-pop. Includes a
Criterion benchmark comparing four strategies (naive, compact,
adaptive, sorted-insert).

Both modules include comprehensive documentation and tests. Neither
references any specific use-case — they are general-purpose building
blocks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant