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.
Lowering values of
future<future<t>>are more complex than normal because in JSPromise<Promise<T>>is automatically resolved toPromise<T>. To properly represent nested futures and use them, we must:Promise<Promise<T>>without collapsingAs of #1422 there is a partial implementation of nested stream lowering in the
Instruction::FutureLowerinstruction, 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 doesLowerIntrinsic::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 thanPromises. This may be preferable to actually trying to coerce Promises to do what we'd like them to do.