Skip to content

Yield with defer queue #459

@Chaoses-Ib

Description

@Chaoses-Ib

tokio has a yield_now() function that can be used to yield the current task. Because the task will be added to the back of the defer queue, it will be scheduled after other pending tasks (though not guaranteed to drive the driver). Is there any equivalent in Compio? Simply using something like the following will make the task be immediately polled again:

pub async fn yield_now() {
    YieldNow(false).await
}

struct YieldNow(bool);

impl Future for YieldNow {
    type Output = ();

    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        if !self.0 {
            self.0 = true;
            cx.waker().wake_by_ref();
            Poll::Pending
        } else {
            Poll::Ready(())
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions