Skip to content

Commit

Permalink
Add 'stream' type
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewagner committed Oct 4, 2024
1 parent ea387d8 commit 92bfd52
Show file tree
Hide file tree
Showing 5 changed files with 969 additions and 106 deletions.
28 changes: 16 additions & 12 deletions design/mvp/Async.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,21 +419,25 @@ For now, this remains a [TODO](#todo) and validation will reject `async`-lifted

## TODO

Native async support is being proposed in progressive chunks. The following
features will be added in future chunks to complete "async" in Preview 3:
* `future`/`stream`/`error`: add for use in function types for finer-grained
concurrency
* `subtask.cancel`: allow a supertask to signal to a subtask that its result is
no longer wanted and to please wrap it up promptly
* allow "tail-calling" a subtask so that the current wasm instance can be torn
down eagerly
* `task.index`+`task.wake`: allow tasks in the same instance to wait on and
wake each other (async condvar-style)
Native async support is being proposed incrementally. The following features
will be added in future chunks roughly in the order list to complete the full
"async" story:
* add `future` type
* add `error` type that can be included when closing a stream/future
* `nonblocking` function type attribute: allow a function to declare in its
type that it will not transitively do anything blocking
* define what `async` means for `start` functions
* `task.index`+`task.wake`: allow tasks in the same instance to wait on and
wake each other
* `subtask.cancel`: allow a supertask to signal to a subtask that its result is
no longer wanted and to please wrap it up promptly
* `stream.lull` built-in that says "no more elements are coming for a while"
* `recursive` function type attribute: allow a function to be reentered
recursively (instead of trapping)
* enable `async` `start` functions
recursively (instead of trapping) for the benefit of donut wrapping
* built-in to "tail-call" a subtask so that the current wasm instance can be torn
down eagerly while preserving "structured concurrency"
* allow pipelining multiple `stream.read`/`write` calls
* allow chaining multiple async calls together ("promise pipelining")
* integrate with `shared`: define how to lift and lower functions `async` *and*
`shared`

Expand Down
1 change: 1 addition & 0 deletions design/mvp/CanonicalABI.md
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,7 @@ where `$callee` has type `$ft`, validation specifies:
* a `memory` is present if required by lifting and is a subtype of `(memory 1)`
* a `realloc` is present if required by lifting and has type `(func (param i32 i32 i32 i32) (result i32))`
* there is no `post-return` in `$opts`
* if `contains_async($ft)`, then `$opts.async` must be set

When instantiating component instance `$inst`:
* Define `$f` to be the partially-bound closure: `canon_lower($opts, $ft, $callee)`
Expand Down
10 changes: 6 additions & 4 deletions design/mvp/Explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -1222,10 +1222,12 @@ freeing memory after lifting and thus `post-return` may be deprecated in the
future.

🔀 The `async` option specifies that the component wants to make (for imports)
or support (for exports) multiple concurrent (asynchronous) calls. This option
can be applied to any component-level function type and changes the derived
Canonical ABI significantly. See the [async explainer](Async.md) for more
details.
or support (for exports) multiple concurrent (asynchronous) calls. This
option can be applied to any component-level function type and changes the
derived Canonical ABI significantly. See the [async explainer](Async.md) for
more details. When a function signature contains a `future` or `stream`,
validation requires the `async` option to be set (since a synchronous call to
a function using these types is likely to deadlock).

🔀 The `(callback ...)` option may only be present in `canon lift` when the
`async` option has also been set and specifies a core function that is
Expand Down
Loading

0 comments on commit 92bfd52

Please sign in to comment.