Skip to content

feat(event): add a manual-reset event - #243

Merged
tisonkun merged 6 commits into
apache:mainfrom
orthur2:feat/manual-reset-event
Aug 30, 2026
Merged

feat(event): add a manual-reset event#243
tisonkun merged 6 commits into
apache:mainfrom
orthur2:feat/manual-reset-event

Conversation

@orthur2

@orthur2 orthur2 commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add opt-in asyncband::event::ManualResetEvent, a reusable level-triggered signal with explicit initial state, state inspection, set, and reset
  • provide async wait and Arc-owning wait_owned methods while keeping their implementation future types private
  • keep registered waits committed across a following reset and isolate cancellation to the dropped wait
  • add contract tests and self-benchmarks for state transitions, waiter lifecycle, reentrancy, and fanout

Design Notes

The event keeps its boolean state and waiter list under one mutex. An unset-to-set transition marks and detaches the complete registered cohort before invoking any waker, so a later reset cannot undo those waits and a reentrant wake callback cannot join the transition already in progress. WaitList retains that per-wait commitment; alternative waiter storage can be explored independently without changing the public API.

Wakers are cloned, invoked, and dropped outside the state lock. Registration rechecks the complete state after cloning a waker because clone callbacks may re-enter the event. If one wake callback panics, the remaining callbacks are still attempted before the first panic resumes.

Waits register on their first poll, not when their futures are constructed. Consequently, set(); reset(); is not a pulse for an unpolled future. An unset-to-set transition publishes preceding writes to waits it releases and to waits first polled while the event remains set; is_set remains only a snapshot.

Validation

  • cargo x check
  • cargo x test
  • cargo x lint

Closes #221.

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an idea that can improve the internal representation. Will create an issue for exploring (I may be wrong).

Push commits to refine APIs and docs. The docs update may be less-than-awesome so feel free to follow-up improve them.

@tisonkun
tisonkun merged commit 5419516 into apache:main Aug 30, 2026
10 checks passed
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.

Provide a manual-reset event

2 participants