pub struct Arbiter { /* private fields */ }
Expand description
An Arbiter represents a thread that provides an asynchronous execution environment for futures and functions.
When an arbiter is created, it spawns a new OS thread, and hosts an event loop.
Implementations
sourceimpl Arbiter
impl Arbiter
sourcepub fn with_tokio_rt<F>(runtime_factory: F) -> Arbiter where
F: Fn() -> Runtime + Send + 'static,
pub fn with_tokio_rt<F>(runtime_factory: F) -> Arbiter where
F: Fn() -> Runtime + Send + 'static,
Spawn a new Arbiter using the Tokio Runtime returned from a closure.
sourcepub fn handle(&self) -> ArbiterHandle
pub fn handle(&self) -> ArbiterHandle
Return a handle to the this Arbiter’s message sender.
sourcepub fn current() -> ArbiterHandle
pub fn current() -> ArbiterHandle
Return a handle to the current thread’s Arbiter’s message sender.
Panics
Panics if no Arbiter is running on the current thread.
sourcepub fn try_current() -> Option<ArbiterHandle>
pub fn try_current() -> Option<ArbiterHandle>
Try to get current running arbiter handle.
Returns None
if no Arbiter has been started.
Unlike current
, this never panics.
sourcepub fn stop(&self) -> bool
pub fn stop(&self) -> bool
Stop Arbiter from continuing it’s event loop.
Returns true if stop message was sent successfully and false if the Arbiter has been dropped.
sourcepub fn spawn<Fut>(&self, future: Fut) -> bool where
Fut: Future<Output = ()> + Send + 'static,
pub fn spawn<Fut>(&self, future: Fut) -> bool where
Fut: Future<Output = ()> + Send + 'static,
Send a future to the Arbiter’s thread and spawn it.
If you require a result, include a response channel in the future.
Returns true if future was sent successfully and false if the Arbiter has died.
sourcepub fn spawn_fn<F>(&self, f: F) -> bool where
F: FnOnce() + Send + 'static,
pub fn spawn_fn<F>(&self, f: F) -> bool where
F: FnOnce() + Send + 'static,
Send a function to the Arbiter’s thread and execute it.
Any result from the function is discarded. If you require a result, include a response channel in the function.
Returns true if function was sent successfully and false if the Arbiter has died.
sourcepub fn join(self) -> Result<()>
pub fn join(self) -> Result<()>
Wait for Arbiter’s event loop to complete.
Joins the underlying OS thread handle. See JoinHandle::join
.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Arbiter
impl Send for Arbiter
impl Sync for Arbiter
impl Unpin for Arbiter
impl !UnwindSafe for Arbiter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more