Why manual call of schedule is needed on runnable?
Closed this issue · 2 comments
npuichigo commented
let schedule = |runnable| QUEUE.send(runnable).unwrap();
let (runnable, task) = async_task::spawn(async { 1 + 2 }, schedule);
// Schedule the task and await its output.
runnable.schedule(); <- this line
assert_eq!(smol::future::block_on(task), 3);
Frankly,it's not very ergonomic. Why not the future starting to be scheduled once it's awaited, just use Rust
lazy future feature.
notgull commented
This is done so that you can manipulate the runnable before scheduling it. For instance, see these lines in async-executor
:
Here we need to get the waker for the runnable before scheduling it. This would be impossible or at least very inefficient if the Runnable
was only created when the future desired it.