rust-dispatch icon indicating copy to clipboard operation
rust-dispatch copied to clipboard

Add Dispatch sources

Open nanotech opened this issue 9 years ago • 1 comments

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_t polymorphism 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_walltime times since there isn't a Rust interface for dispatch_time_t yet.
  • I removed the dispatch_source_set_event_handler interface in the second commit as it's the only new symbol here not supported on most other distributions. Might want to use the same cfg as QueueAttribute instead, or better, add library version detection to a build.rs.
  • The impl_source_type macro doesn't save that much code.
  • The new bitflags and especially libc dependencies 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.

nanotech avatar Oct 08 '16 05:10 nanotech

Hello, what is the status of this? I would like to use dispatch sources. Will this pr get reviewed/merged?

manuel-rhdt avatar Oct 15 '17 11:10 manuel-rhdt