Skip to content

rust: make FutureWaker component-model-task-aware #1431

@dicej

Description

@dicej

Currently wit_bindgen::rt::async_support contains a FutureWaker type used to determine whether to return CALLBACK_CODE_YIELD or CALLBACK_CODE_WAIT when the Future corresponding to a given task returns Poll::Pending. However, it ought to be a bit smarter with regards to inter-task communication.

Consider a scenario involving two concurrent tasks: A and B:

  1. A creates a oneshot channel and stores the write end in a global variable, then awaits the read end, returning CALLBACK_CODE_WAIT to the host
  2. B writes to the write end, waking A's waker

In this case, waking A's waker should have the effect of telling the host to resume A; currently it does not. I imagine the waker could create a new payload-less future, call future.read on the read end (which would return RETURN_CODE_BLOCKED), add the read end to A's waitable-set, then call future.write on the write end, causing the host to eventually call the callback for A. Alternatively, we could either proactively or lazily create a payload-less stream for each task and reuse it as needed. Once we have cooperative multithreading support, we could simplify that to just calling e.g. thread.switch-to -- no future or stream needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions