Skip to main content

CoroutineContext

Struct CoroutineContext 

Source
pub struct CoroutineContext<SerializedData: 'static + Send> {
    pub serializer: Serializer<(CoroutineSharedData, SerializedData)>,
    pub task_id: u32,
    /* private fields */
}
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§

Source§

impl<SD: 'static + Send> CoroutineContext<SD>

Source

pub async fn main_context(shared_data: SD) -> Self

Creates a new, main coroutine context with given shared_data

Source

pub fn child_context( serializer: Serializer<(CoroutineSharedData, SD)>, permit: SerializerLock<'static, (CoroutineSharedData, SD)>, task_id: u32, ) -> Self

Source

pub fn get_shared_data_mut(&mut self) -> &mut SD

Given the fact that the permit is held, and there’s not another mutable reference to the shared data, retrieve the shared data.

Source

pub async fn co_yield(&self)

Interrupt current task, allowing other task to run.

Source

pub async fn co_await<FUT, RET>(&self, fut: FUT) -> RET
where FUT: Future<Output = RET>, RET: Send + Sync,

Interrupt current task, await for given fut. During this time other tasks may run.

Source

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

Source

pub async fn finish(&self)

Called on main task exit, wait for all other tasks to finish.

Trait Implementations§

Source§

impl<SD: 'static + Send> Drop for CoroutineContext<SD>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<SD: 'static + Send> Send for CoroutineContext<SD>

Source§

impl<SD: 'static + Send> Sync for CoroutineContext<SD>

Auto Trait Implementations§

§

impl<SerializedData> !Freeze for CoroutineContext<SerializedData>

§

impl<SerializedData> !RefUnwindSafe for CoroutineContext<SerializedData>

§

impl<SerializedData> !UnwindSafe for CoroutineContext<SerializedData>

§

impl<SerializedData> Unpin for CoroutineContext<SerializedData>

§

impl<SerializedData> UnsafeUnpin for CoroutineContext<SerializedData>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.