Skip to content

Implement non-Promise collapsed future<future<T>> lowering in async calls #1430

@vados-cosmonic

Description

@vados-cosmonic

Lowering values of future<future<t>> are more complex than normal because in JS Promise<Promise<T>> is automatically resolved to Promise<T>. To properly represent nested futures and use them, we must:

  • Spontaneously create the right number of component-internal future waitable objects
  • Ensure that when host writes are injected (i.e. just before a guest read where the host holds the write end), we possibly turn the value into a promise
  • Lifting a nested future wraps the value going out into something that behaves like a Promise<Promise<T>> without collapsing
  • For the component the future is being lowered into, and make sure that when

As of #1422 there is a partial implementation of nested stream lowering in the Instruction::FutureLower instruction, which produces a "Thenable" that does essentially counting to replicate the idea of a future that resolves nestedly, but this implementation does not yet work and neither does LowerIntrinsic::LowerFlatFuture.

(we should also de-duplicate both lowers but that's a discussion for another day)

An entirely workable solution is also to require that nested futures passed from javascript are of a different form, or to treat futures as AsyncIterators, rather than Promises. This may be preferable to actually trying to coerce Promises to do what we'd like them to do.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions