rust-dispatch
rust-dispatch copied to clipboard
Add Dispatch sources
Some rationale on interface choices:
- Sources are created with a SourceBuilder so they are started with all their handlers configured, and the initial resume is called at most once.
- Sources are parameterized on their SourceType so certain methods can be statically restricted to sources of the appropriate type.
- The source is passed to handlers so the user doesn't need to create and break a retain cycle themselves to call
.data()or.cancel()from the handler. - SuspendGuard can suspend and resume both Queues and Sources now, and uses
dispatch_object_tpolymorphism internally to avoid public API changes. - BoxedOnceHandler allows for both FnOnce types and non-leaking early drop on the registration and cancel handlers.
Some things that could be improved:
- Timers can't be scheduled to
dispatch_walltimetimes since there isn't a Rust interface fordispatch_time_tyet. - I removed the
dispatch_source_set_event_handlerinterface in the second commit as it's the only new symbol here not supported on most other distributions. Might want to use the samecfgas QueueAttribute instead, or better, add library version detection to a build.rs. - The
impl_source_typemacro doesn't save that much code. - The new
bitflagsand especiallylibcdependencies aren't that big and could be removed if you want to retain zero dependencies. - Source types could use a different construction pattern to reduce verbosity and breakage if flags are added to types currently without them.
Hello, what is the status of this? I would like to use dispatch sources. Will this pr get reviewed/merged?