pub struct LocalSpawner<C, T> { /* private fields */ }
Implementations§
Source§impl<C: 'static + Send, T: Task<C> + 'static + Send> LocalSpawner<C, T>
impl<C: 'static + Send, T: Task<C> + 'static + Send> LocalSpawner<C, T>
Sourcepub fn new_current() -> Self
pub fn new_current() -> Self
Create a new LocalSpawner
instance use [tokio::runtime::Builder::new_current_thread]
.
Sourcepub fn new(runtime: Option<Arc<Runtime>>) -> Self
pub fn new(runtime: Option<Arc<Runtime>>) -> Self
Create a new LocalSpawner
instance use supplied [tokio::runtime::Runtime]
.
Sourcepub fn spawn(&self, task: T, tx: Sender<TaskHandler<C>>)
pub fn spawn(&self, task: T, tx: Sender<TaskHandler<C>>)
Spawn a task
This will kick task to start it’s main handler loop.
User need to prepare a [tokio::sync::oneshot]
channel to receive notification
when task successful started.
§Example
let spawner = LocalSpawner::new_current();
let (tx, rx) = oneshot::channel();
let file = File::new(1);
spawner.spawn(file, tx);
let handler1 = rx.blocking_recv().expect("failed to get back file handler");
Trait Implementations§
Auto Trait Implementations§
impl<C, T> Freeze for LocalSpawner<C, T>
impl<C, T> RefUnwindSafe for LocalSpawner<C, T>
impl<C, T> Send for LocalSpawner<C, T>
impl<C, T> Sync for LocalSpawner<C, T>
impl<C, T> Unpin for LocalSpawner<C, T>
impl<C, T> UnwindSafe for LocalSpawner<C, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more