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

Provide a publicly-accessible Core ID #149

Merged
merged 1 commit into from
Jan 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/reactor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ struct Inner {
timeouts: Slab<(Option<Slot>, TimeoutState)>,
}

/// An unique ID for a Core
///
/// An ID by which different cores may be distinguished. Can be compared and used as an index in
/// a `HashMap`.
///
/// The ID is globally unique and never reused.
#[derive(Clone,Copy,Eq,PartialEq,Hash,Debug)]
pub struct CoreId(usize);

/// Handle to an event loop, used to construct I/O objects, send messages, and
/// otherwise interact indirectly with the event loop itself.
///
Expand Down Expand Up @@ -420,6 +429,11 @@ impl Core {
Message::Run(r) => r.call_box(self),
}
}

/// Get the ID of this loop
pub fn id(&self) -> CoreId {
CoreId(self.inner.borrow().id)
}
}

impl Inner {
Expand Down Expand Up @@ -589,6 +603,11 @@ impl Remote {
lp.inner.borrow_mut().spawn(Box::new(f.into_future()));
})));
}

/// Return the ID of the represented Core
pub fn id(&self) -> CoreId {
CoreId(self.id)
}
}

impl Handle {
Expand Down Expand Up @@ -620,6 +639,11 @@ impl Handle {
{
self.spawn(futures::lazy(f))
}

/// Return the ID of the represented Core
pub fn id(&self) -> CoreId {
self.remote.id()
}
}

impl TimeoutState {
Expand Down