Struct pr47::util::serializer::CoroutineContext [−][src]
pub struct CoroutineContext<SerializedData: 'static + Send> {
pub serializer: Serializer<(CoroutineSharedData, SerializedData)>,
pub task_id: u32,
// some fields omitted
}
Expand description
Context of one coroutine/task
Fields
serializer: Serializer<(CoroutineSharedData, SerializedData)>
Data shared by all tasks in the same serialization group.
task_id: u32
Task ID of the current task. 0
implies main task, while other values are used for
children tasks.
Implementations
Creates a new, main coroutine context with given shared_data
pub fn child_context(
serializer: Serializer<(CoroutineSharedData, SD)>,
permit: SerializerLock<'static, (CoroutineSharedData, SD)>,
task_id: u32
) -> Self
Given the fact that the permit is held, and there’s not another mutable reference to the shared data, retrieve the shared data.
Interrupt current task
, await for given fut
. During this time other task
s may run.
pub async fn co_spawn_task<FN, ARGS, FUT, RET>(
&self,
f: FN,
args: ARGS
) -> JoinHandle<RET> where
FN: FnOnce(CoroutineContext<SD>, ARGS) -> FUT + Send + 'static,
ARGS: Send + 'static,
FUT: Future<Output = RET> + Send,
RET: Send + 'static,
pub async fn co_spawn_task<FN, ARGS, FUT, RET>(
&self,
f: FN,
args: ARGS
) -> JoinHandle<RET> where
FN: FnOnce(CoroutineContext<SD>, ARGS) -> FUT + Send + 'static,
ARGS: Send + 'static,
FUT: Future<Output = RET> + Send,
RET: Send + 'static,
Spawn a new task
managed by the current serialization group