Function async_task::spawn_unchecked
source · pub unsafe fn spawn_unchecked<F, S>(
future: F,
schedule: S,
) -> (Runnable, Task<F::Output>)
Expand description
Creates a new task without Send
, Sync
, and 'static
bounds.
This function is same as spawn()
, except it does not require Send
, Sync
, and
'static
on future
and schedule
.
§Safety
- If
future
is notSend
, itsRunnable
must be used and dropped on the original thread. - If
future
is not'static
, borrowed variables must outlive itsRunnable
. - If
schedule
is notSend
andSync
, all instances of theRunnable
’sWaker
must be used and dropped on the original thread. - If
schedule
is not'static
, borrowed variables must outlive all instances of theRunnable
’sWaker
.
§Examples
// The future inside the task.
let future = async {
println!("Hello, world!");
};
// If the task gets woken up, it will be sent into this channel.
let (s, r) = flume::unbounded();
let schedule = move |runnable| s.send(runnable).unwrap();
// Create a task with the future and the schedule function.
let (runnable, task) = unsafe { async_task::spawn_unchecked(future, schedule) };