mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00
Provide a publicly-accessible Core ID
Allow distinguishing between multiple `Core`s and associating data with them through a `HashMap` or similar.
This commit is contained in:
parent
d0833074d6
commit
8d02a1c2b6
@ -76,6 +76,15 @@ struct Inner {
|
|||||||
timeouts: Slab<(Option<Slot>, TimeoutState)>,
|
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
|
/// Handle to an event loop, used to construct I/O objects, send messages, and
|
||||||
/// otherwise interact indirectly with the event loop itself.
|
/// otherwise interact indirectly with the event loop itself.
|
||||||
///
|
///
|
||||||
@ -420,6 +429,11 @@ impl Core {
|
|||||||
Message::Run(r) => r.call_box(self),
|
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 {
|
impl Inner {
|
||||||
@ -589,6 +603,11 @@ impl Remote {
|
|||||||
lp.inner.borrow_mut().spawn(Box::new(f.into_future()));
|
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 {
|
impl Handle {
|
||||||
@ -620,6 +639,11 @@ impl Handle {
|
|||||||
{
|
{
|
||||||
self.spawn(futures::lazy(f))
|
self.spawn(futures::lazy(f))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the ID of the represented Core
|
||||||
|
pub fn id(&self) -> CoreId {
|
||||||
|
self.remote.id()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TimeoutState {
|
impl TimeoutState {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user