嗨,我正在查看的文档
asnyc_task
请注意,在示例代码中:
use async_task::Runnable;
use flume::{Receiver, Sender};
use std::rc::Rc;
thread_local! {
// A queue that holds scheduled tasks.
static QUEUE: (Sender<Runnable>, Receiver<Runnable>) = flume::unbounded();
}
// Make a non-Send future.
let msg: Rc<str> = "Hello, world!".into();
let future = async move {
println!("{}", msg);
};
// A function that schedules the task when it gets woken up.
let s = QUEUE.with(|(s, _)| s.clone());
let schedule = move |runnable| s.send(runnable).unwrap();
// Create a task with the future and the schedule function.
let (runnable, task) = async_task::spawn_local(future, schedule);
当涉及到的函数签名时
::spawn_local(...)
有一个特点
Schedule
pub fn spawn_local<F, S>(future: F, schedule: S) -> (Runnable, Task<F::Output>)
where
F: Future + 'static,
F::Output: 'static,
S: Schedule + Send + Sync + 'static,
哪里
日程
具有以下特征:
pub trait Schedule<M = ()>: Sealed<M> {
// Required method
fn schedule(&self, runnable: Runnable<M>, info: ScheduleInfo);
}
在我看来,以下代码丢失了
info: ScheduleInfo
作为一个论点,所以我想知道这种特质界限是如何得到满足的。
let schedule = move |runnable| s.send(runnable).unwrap();