You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/fibers/Explainer.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -202,19 +202,19 @@ This, in turn, means that a fiber manager may be relieved of the burden of commu
202
202
203
203
#### `fiber.retire` Retire a fiber
204
204
205
-
The `fiber.retire` instruction is used when a fiber has finished its work and wishes to inform its parent of any final results. Like `fiber.suspend` (and `fiber.resume`), `fiber.retire` has an event argument—together with associated values on the agument stack— that are communicated.
205
+
The `fiber.retire` instruction is used when a fiber has finished its work and wishes to inform its parent of any final results. Like `fiber.suspend` (and `fiber.resume`), `fiber.retire` has an event argument—together with associated values on the argument stack— that are communicated.
206
206
207
207
In addition, the retiring fiber is put into a moribund state and any computation resources associated with it are released. If the fiber has any active descendants then they too are made moribund.
208
208
209
209
>It is not recommended that a fiber allows exceptions to be propagated out of the fiber function. Instead, the function should use a `fiber.retire`—together with an appropriate event description—to signal the exceptional return. This allows the resume ancestor to directly capture the exceptional event as part of its normal response to the resume.
210
210
211
-
>The reason that we don't recommend allowing exceptions to propagate is that an inapprpriate exception handler may be invoked as a result. This is especially dangerous in the case that the retiring fiber was switched to—with a `fiber.switch` instruction—rather than being resumed.
211
+
>The reason that we don't recommend allowing exceptions to propagate is that an inappropriate exception handler may be invoked as a result. This is especially dangerous in the case that the retiring fiber was switched to—with a `fiber.switch` instruction—rather than being resumed.
212
212
213
213
#### `fiber.retireto` Retire a fiber and directly switch
214
214
215
215
The `fiber.retireto` instruction is used when a fiber has finished its work and wishes to switch to another fiber. This is analogous to tail recursive calls of functions: the current fiber is retiring and another fiber is resumed.
216
216
217
-
The `fiber.retireto` instruction has three operands: the identity of the fiber being retired, the identity of the fiber being resumed and an event —together with associated values on the agument stack—to communicate to the newly resumed fiber.
217
+
The `fiber.retireto` instruction has three operands: the identity of the fiber being retired, the identity of the fiber being resumed and an event —together with associated values on the argument stack—to communicate to the newly resumed fiber.
218
218
219
219
In addition, the retiring fiber is put into a moribund state and any computation resources associated with it are released.
220
220
@@ -303,7 +303,7 @@ During normal execution, the `$arrayGenerator` is always waiting for an `$next`
303
303
304
304
Notice that the array generator has definite knowledge of its own fiber—it is given the identity of its fiber explictly. This is needed because when a fiber suspends, it must use the identity of the fiber that is suspending. There is no implicit searching for which computation to suspend.
305
305
306
-
The end of the `$arrayGenerator`&mdashwhich is triggered when there are no more elements to generate—is marked by a simple `return`. This will terminate the fiber and also signal to the consumer that generation has finished.
306
+
The end of the `$arrayGenerator`—which is triggered when there are no more elements to generate—is marked by a simple `return`. This will terminate the fiber and also signal to the consumer that generation has finished.
307
307
308
308
#### Consuming generated elements
309
309
The consumer side of the generator/consumer scenario is similar to the generator; with a few key differences:
@@ -871,4 +871,4 @@ When a `fiber` terminates, the stack resources it uses may be released; however,
871
871
872
872
An alternative approach could be based on _reusing_`fiber` references. In particular, if we allow a moribund fiber to be reused then the issue of garbage collecting old `fiber` references becomes a problem for the toolchain to address: it would become responsible for managing the `fiber` references it has access to.
873
873
874
-
A further restriction would enhance this: if the only place where a `fiber` reference could be stored was in a table, then, if the default value for a `fiber` table entry were a moribund `fiber`, complete reponsibility for managing `fiber` references could be left to the toolchain.
874
+
A further restriction would enhance this: if the only place where a `fiber` reference could be stored was in a table, then, if the default value for a `fiber` table entry were a moribund `fiber`, complete reponsibility for managing `fiber` references could be left to the toolchain.
0 commit comments