Function stakker_async_await::spawn_future[][src]

pub fn spawn_future<T>(
    core: &mut Core,
    future: impl Future<Output = T> + 'static,
    ret: Ret<T>
)

Spawn a Future and pass the final result to the given Ret

This call does not support the std::task::Waker mechanism which might be required by some futures. Use spawn_with_waker if you need that. The final returned value is sent to ret as Some(value). However if the the last reference to the task is lost (e.g. an actor fails that is required to provide data for the future), it sends None.

This call follows the Stakker convention of using absolutely no synchronization: i.e. no mutexes, no atomics, etc. Since std::task::Waker is Send and so requires atomics or mutexes and cross-thread signalling to operate, that cannot be used for wake-ups. An alternative Stakker-specific same-thread synchronization-free mechanism is used instead by the trait interfaces defined in this crate. So long as the future only ever blocks on the trait interfaces defined in this crate, everything will run fine. If it blocks on other things then you will get a panic and need to use spawn_future_with_waker instead.

This call sets up the task and execution is deferred to the queue. The task will then automatically execute in segments (from yield to yield) as data it requires becomes available, until it completes or is dropped. Normally before a future yields, the handling code takes a reference to the task using current_task and stores it in a stakker::Ret or stakker::Fwd which resumes the task once data becomes ready.