Skip to content

Commit 4da97f2

Browse files
chore: clarify the function being referred to
Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
1 parent 2cf3e4b commit 4da97f2

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

design/mvp/Async.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,8 @@ world w {
723723
export foo: func(s: string) -> string;
724724
}
725725
```
726-
the default sync export function signature is:
726+
727+
The default sync export function signature for export `foo` is:
727728
```wat
728729
;; sync
729730
(func (param $s-ptr i32) (param $s-len i32) (result $retp i32))
@@ -739,33 +740,43 @@ The async export ABI provides two flavors: stackful and stackless.
739740

740741
The stackful ABI is currently gated by the 🚟 feature.
741742

742-
The async stackful export function signature is:
743+
The async stackful export function signature for export `foo` (defined above
744+
in world `w`) is:
745+
743746
```wat
744747
;; async, no callback
745748
(func (param $s-ptr i32) (param $s-len i32))
746749
```
747-
The parameters work just like synchronous parameters. There is no core function
748-
result because a callee [returns](#returning) their value by *calling* the
749-
*imported* `task.return` function which has signature:
750+
751+
The parameters work just like synchronous parameters.
752+
753+
There is no core function result because a callee [returns](#returning) their
754+
value by *calling* the *imported* `task.return` function which has signature:
755+
750756
```wat
751757
;; task.return
752758
(func (param $ret-ptr i32) (result $ret-len i32))
753759
```
760+
754761
The parameters of `task.return` work the same as if the WIT return type was the
755762
WIT parameter type of a synchronous function. For example, if more than 16
756763
core parameters would be needed, a single `i32` pointer into linear memory is
757764
used.
758765

759766
##### Stackless Async Exports
760767

761-
The async stackless export function signature is:
768+
The async stackless export function signature for export `foo` (defined above
769+
in world `w`) is:
770+
762771
```wat
763772
;; async, callback
764773
(func (param $s-ptr i32) (param $s-len i32) (result i32))
765774
```
775+
766776
The parameters also work just like synchronous parameters. The callee returns
767-
their value by calling `task.return` just like the stackful case. The `(result
768-
i32)` lets the core function return what it wants the runtime to do next:
777+
their value by calling `task.return` just like the stackful case.
778+
779+
The `(result i32)` lets the core function return what it wants the runtime to do next:
769780
* If the low 4 bits are `0`, the callee completed (and called `task.return`)
770781
without blocking.
771782
* If the low 4 bits are `1`, the callee wants to yield, allowing other code
@@ -777,9 +788,11 @@ i32)` lets the core function return what it wants the runtime to do next:
777788

778789
When an async stackless function is exported, a companion "callback" function
779790
must also be exported with signature:
791+
780792
```wat
781793
(func (param i32 i32 i32) (result i32))
782794
```
795+
783796
The `(result i32)` has the same interpretation as the stackless export function
784797
and the runtime will repeatedly call the callback until a value of `0` is
785798
returned. The `i32` parameters describe what happened that caused the callback

0 commit comments

Comments
 (0)