Skip to content

Commit 9586b4f

Browse files
committed
Further reword/reorder Concurrency.md#returning
1 parent a7095d4 commit 9586b4f

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

design/mvp/Concurrency.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -685,26 +685,26 @@ the "started" state.
685685

686686
### Returning
687687

688-
The way an async export call returns its value is by calling [`task.return`],
689-
passing the core values that are to be lifted as *parameters*.
688+
The way an `async` export returns its value using the async ABI is by calling
689+
[`task.return`], passing the core values that are to be lifted as *parameters*.
690+
When using the async ABI, *any* of the threads contained by a task can call
691+
`task.return`; there is no "main thread" of a task. When the last thread of a
692+
task returns, there is a trap if `task.return` has not been called. Thus, *some*
693+
thread (either the thread created implicitly for the initial export call or some
694+
thread transitively created by that thread) must call `task.return`.
690695

691696
Returning values by calling `task.return` allows a task to continue executing
692-
even after it has passed its initial results to the caller. This can be useful
693-
for various finalization tasks (freeing memory or performing logging, billing
694-
or metrics operations) that don't need to be on the critical path of returning
695-
a value to the caller, but the major use of executing code after `task.return`
696-
is to continue to read and write from streams and futures. For example, a
697-
stream transformer function of type `func(in: stream<T>) -> stream<U>` will
698-
immediately `task.return` a stream created via `stream.new` and then sit in a
699-
loop interleaving `stream.read`s (of the readable end passed for `in`) and
700-
`stream.write`s (of the writable end it `stream.new`ed) before exiting the
701-
task.
702-
703-
*Any* of the threads contained by a task can call `task.return`; there is no
704-
"main thread" of a task. When the last thread of a task returns, there is a
705-
trap if `task.return` has not been called. Thus, *some* thread (either the
706-
thread created implicitly for the initial export call or some thread
707-
transitively created by that thread) must call `task.return`.
697+
even after it has passed its initial results to the caller. This is also
698+
possible even with the sync ABI by using cooperative threads. Continuing
699+
to execute after returning a value can be useful for various finalization tasks
700+
(freeing memory or performing logging, billing or metrics operations) that don't
701+
need to be on the critical path of returning a value to the caller, but the
702+
major use of executing code after `task.return` is to continue to read and write
703+
from streams and futures. For example, a stream transformer function of type
704+
`func(in: stream<T>) -> stream<U>` will immediately `task.return` a stream
705+
created via `stream.new` and then sit in a loop interleaving `stream.read`s (of
706+
the readable end passed for `in`) and `stream.write`s (of the writable end it
707+
`stream.new`ed) before exiting the task.
708708

709709
Once `task.return` is called, the task is in the "returned" state. Calling
710710
`task.return` when not in the "started" state traps. Once in a "returned" state,

0 commit comments

Comments
 (0)