Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dispatch sources #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

nanotech
Copy link

@nanotech nanotech commented Oct 8, 2016

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.

@manuel-rhdt
Copy link

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

It's first available in the libdispatch from 10.7,
which is newer than is packaged for most
other platforms.
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.

None yet

2 participants