Skip to content

Commit ec584b4

Browse files
committed
Update documentation.
1 parent 225ab4f commit ec584b4

File tree

4 files changed

+62
-62
lines changed

4 files changed

+62
-62
lines changed

context/scheduler.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Async do |task|
3838
task.print_hierarchy($stderr)
3939

4040
# Kill the subtask
41-
subtask.stop
41+
subtask.cancel
4242
end
4343
~~~
4444

@@ -69,9 +69,9 @@ end
6969

7070
You can use this approach to embed the reactor in another event loop. For some integrations, you may want to specify the maximum time to wait to {ruby Async::Scheduler#run_once}.
7171

72-
### Stopping a Scheduler
72+
### Cancelling a Scheduler
7373

74-
{ruby Async::Scheduler#stop} will stop the current scheduler and all children tasks.
74+
{ruby Async::Scheduler#cancel} will cancel the current scheduler and all children tasks.
7575

7676
### Fiber Scheduler Integration
7777

context/tasks.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This guide explains how asynchronous tasks work and how to use them.
44

55
## Overview
66

7-
Tasks are the smallest unit of sequential code execution in {ruby Async}. Tasks can create other tasks, and Async tracks the parent-child relationship between tasks. When a parent task is stopped, it will also stop all its children tasks. The reactor always starts with one root task.
7+
Tasks are the smallest unit of sequential code execution in {ruby Async}. Tasks can create other tasks, and Async tracks the parent-child relationship between tasks. When a parent task is cancelled, it will also cancel all its children tasks. The reactor always starts with one root task.
88

99
```mermaid
1010
graph LR
@@ -23,11 +23,11 @@ graph LR
2323

2424
A fiber is a lightweight unit of execution that can be suspended and resumed at specific points. After a fiber is suspended, it can be resumed later at the same point with the same execution state. Because only one fiber can execute at a time, they are often referred to as a mechanism for cooperative concurrency.
2525

26-
A task provides extra functionality on top of fibers. A task behaves like a promise: it either succeeds with a value or fails with an exception. Tasks keep track of their parent-child relationships, and when a parent task is stopped, it will also stop all its children tasks. This makes it easier to create complex programs with many concurrent tasks.
26+
A task provides extra functionality on top of fibers. A task behaves like a promise: it either succeeds with a value or fails with an exception. Tasks keep track of their parent-child relationships, and when a parent task is cancelled, it will also cancel all its children tasks. This makes it easier to create complex programs with many concurrent tasks.
2727

2828
### Why does Async manipulate tasks and not fibers?
2929

30-
The {ruby Async::Scheduler} actually works directly with fibers for most operations and isn't aware of tasks. However, the reactor does maintain a tree of tasks for the purpose of managing task and reactor life-cycle. For example, stopping a parent task will stop all its children tasks, and the reactor will exit when all tasks are finished.
30+
The {ruby Async::Scheduler} actually works directly with fibers for most operations and isn't aware of tasks. However, the reactor does maintain a tree of tasks for the purpose of managing task and reactor life-cycle. For example, cancelling a parent task will cancel all its children tasks, and the reactor will exit when all tasks are finished.
3131

3232
## Task Lifecycle
3333

@@ -40,20 +40,20 @@ stateDiagram-v2
4040
4141
running --> failed : unhandled StandardError-derived exception
4242
running --> complete : user code finished
43-
running --> stopped : stop
43+
running --> cancelled : cancel
4444
45-
initialized --> stopped : stop
45+
initialized --> cancelled : cancel
4646
4747
failed --> [*]
4848
complete --> [*]
49-
stopped --> [*]
49+
cancelled --> [*]
5050
```
5151

52-
Tasks are created in the `initialized` state, and are run by the reactor. During the execution, a task can either `complete` successfully, become `failed` with an unhandled `StandardError`-derived exception, or be explicitly `stopped`. In all of these cases, you can wait for a task to complete by using {ruby Async::Task#wait}.
52+
Tasks are created in the `initialized` state, and are run by the reactor. During the execution, a task can either `complete` successfully, become `failed` with an unhandled `StandardError`-derived exception, or be explicitly `cancelled`. In all of these cases, you can wait for a task to complete by using {ruby Async::Task#wait}.
5353

5454
1. In the case the task successfully completed, the result will be whatever value was generated by the last expression in the task.
5555
2. In the case the task failed with an unhandled `StandardError`-derived exception, waiting on the task will re-raise the exception.
56-
3. In the case the task was stopped, the result will be `nil`.
56+
3. In the case the task was cancelled, the result will be `nil`.
5757

5858
## Starting A Task
5959

@@ -175,8 +175,8 @@ Async do
175175
break if done.size >= 2
176176
end
177177
ensure
178-
# The remainder of the tasks will be stopped:
179-
barrier.stop
178+
# The remainder of the tasks will be cancelled:
179+
barrier.cancel
180180
end
181181
end
182182
```
@@ -199,18 +199,18 @@ begin
199199
# Wait until all jobs are done:
200200
barrier.wait
201201
ensure
202-
# Stop any remaining jobs:
203-
barrier.stop
202+
# Cancel any remaining jobs:
203+
barrier.cancel
204204
end
205205
~~~
206206

207-
## Stopping a Task
207+
## Cancelling a Task
208208

209209
When a task completes execution, it will enter the `complete` state (or the `failed` state if it raises an unhandled exception).
210210

211-
There are various situations where you may want to stop a task ({ruby Async::Task#stop}) before it completes. The most common case is shutting down a server. A more complex example is this: you may fan out multiple (10s, 100s) of requests, wait for a subset to complete (e.g. the first 5 or all those that complete within a given deadline), and then stop (terminate/cancel) the remaining operations.
211+
There are various situations where you may want to cancel a task ({ruby Async::Task#cancel}) before it completes. The most common case is shutting down a server. A more complex example is this: you may fan out multiple (10s, 100s) of requests, wait for a subset to complete (e.g. the first 5 or all those that complete within a given deadline), and then cancel the remaining operations.
212212

213-
Using the above program as an example, let's stop all the tasks just after the first one completes.
213+
Using the above program as an example, let's cancel all the tasks just after the first one completes.
214214

215215
```ruby
216216
Async do
@@ -221,14 +221,14 @@ Async do
221221
end
222222
end
223223

224-
# Stop all the above tasks:
225-
tasks.each(&:stop)
224+
# Cancel all the above tasks:
225+
tasks.each(&:cancel)
226226
end
227227
```
228228

229-
### Stopping all Tasks held in a Barrier
229+
### Cancelling all Tasks held in a Barrier
230230

231-
To stop (terminate/cancel) all the tasks held in a barrier:
231+
To cancel all the tasks held in a barrier:
232232

233233
```ruby
234234
barrier = Async::Barrier.new
@@ -241,11 +241,11 @@ Async do
241241
end
242242
end
243243

244-
barrier.stop
244+
barrier.cancel
245245
end
246246
```
247247

248-
Unless your tasks all rescue and suppresses `StandardError`-derived exceptions, be sure to call ({ruby Async::Barrier#stop}) to stop the remaining tasks:
248+
Unless your tasks all rescue and suppresses `StandardError`-derived exceptions, be sure to call ({ruby Async::Barrier#cancel}) to cancel the remaining tasks:
249249

250250
```ruby
251251
barrier = Async::Barrier.new
@@ -261,7 +261,7 @@ Async do
261261
begin
262262
barrier.wait
263263
ensure
264-
barrier.stop
264+
barrier.cancel
265265
end
266266
end
267267
```
@@ -273,10 +273,10 @@ In order to ensure your resources are cleaned up correctly, make sure you wrap r
273273
~~~ ruby
274274
Async do
275275
begin
276-
socket = connect(remote_address) # May raise Async::Stop
276+
socket = connect(remote_address) # May raise Async::Cancel
277277

278-
socket.write(...) # May raise Async::Stop
279-
socket.read(...) # May raise Async::Stop
278+
socket.write(...) # May raise Async::Cancel
279+
socket.read(...) # May raise Async::Cancel
280280
ensure
281281
socket.close if socket
282282
end
@@ -398,9 +398,9 @@ end
398398

399399
Transient tasks are similar to normal tasks, except for the following differences:
400400

401-
1. They are not considered by {ruby Async::Task#finished?}, so they will not keep the reactor alive. Instead, they are stopped (with a {ruby Async::Stop} exception) when all other (non-transient) tasks are finished.
401+
1. They are not considered by {ruby Async::Task#finished?}, so they will not keep the reactor alive. Instead, they are cancelled (with a {ruby Async::Cancel} exception) when all other (non-transient) tasks are finished.
402402
2. As soon as a parent task is finished, any transient child tasks will be moved up to be children of the parent's parent. This ensures that they never keep a sub-tree alive.
403-
3. Similarly, if you `stop` a task, any transient child tasks will be moved up the tree as above rather than being stopped.
403+
3. Similarly, if you `cancel` a task, any transient child tasks will be moved up the tree as above rather than being cancelled.
404404

405405
The purpose of transient tasks is when a task is an implementation detail of an object or instance, rather than a concurrency process. Some examples of transient tasks:
406406

@@ -439,7 +439,7 @@ class TimeStringCache
439439
sleep(1)
440440
end
441441
ensure
442-
# When the reactor terminates all tasks, `Async::Stop` will be raised from `sleep` and this code will be invoked. By clearing `@refresh`, we ensure that the task will be recreated if needed again:
442+
# When the reactor terminates all tasks, `Async::Cancel` will be raised from `sleep` and this code will be invoked. By clearing `@refresh`, we ensure that the task will be recreated if needed again:
443443
@refresh = nil
444444
end
445445
end

guides/scheduler/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Async do |task|
3838
task.print_hierarchy($stderr)
3939

4040
# Kill the subtask
41-
subtask.stop
41+
subtask.cancel
4242
end
4343
~~~
4444

@@ -69,9 +69,9 @@ end
6969

7070
You can use this approach to embed the reactor in another event loop. For some integrations, you may want to specify the maximum time to wait to {ruby Async::Scheduler#run_once}.
7171

72-
### Stopping a Scheduler
72+
### Cancelling a Scheduler
7373

74-
{ruby Async::Scheduler#stop} will stop the current scheduler and all children tasks.
74+
{ruby Async::Scheduler#cancel} will cancel the current scheduler and all children tasks.
7575

7676
### Fiber Scheduler Integration
7777

guides/tasks/readme.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This guide explains how asynchronous tasks work and how to use them.
44

55
## Overview
66

7-
Tasks are the smallest unit of sequential code execution in {ruby Async}. Tasks can create other tasks, and Async tracks the parent-child relationship between tasks. When a parent task is stopped, it will also stop all its children tasks. The reactor always starts with one root task.
7+
Tasks are the smallest unit of sequential code execution in {ruby Async}. Tasks can create other tasks, and Async tracks the parent-child relationship between tasks. When a parent task is cancelled, it will also cancel all its children tasks. The reactor always starts with one root task.
88

99
```mermaid
1010
graph LR
@@ -23,11 +23,11 @@ graph LR
2323

2424
A fiber is a lightweight unit of execution that can be suspended and resumed at specific points. After a fiber is suspended, it can be resumed later at the same point with the same execution state. Because only one fiber can execute at a time, they are often referred to as a mechanism for cooperative concurrency.
2525

26-
A task provides extra functionality on top of fibers. A task behaves like a promise: it either succeeds with a value or fails with an exception. Tasks keep track of their parent-child relationships, and when a parent task is stopped, it will also stop all its children tasks. This makes it easier to create complex programs with many concurrent tasks.
26+
A task provides extra functionality on top of fibers. A task behaves like a promise: it either succeeds with a value or fails with an exception. Tasks keep track of their parent-child relationships, and when a parent task is cancelled, it will also cancel all its children tasks. This makes it easier to create complex programs with many concurrent tasks.
2727

2828
### Why does Async manipulate tasks and not fibers?
2929

30-
The {ruby Async::Scheduler} actually works directly with fibers for most operations and isn't aware of tasks. However, the reactor does maintain a tree of tasks for the purpose of managing task and reactor life-cycle. For example, stopping a parent task will stop all its children tasks, and the reactor will exit when all tasks are finished.
30+
The {ruby Async::Scheduler} actually works directly with fibers for most operations and isn't aware of tasks. However, the reactor does maintain a tree of tasks for the purpose of managing task and reactor life-cycle. For example, cancelling a parent task will cancel all its children tasks, and the reactor will exit when all tasks are finished.
3131

3232
## Task Lifecycle
3333

@@ -40,20 +40,20 @@ stateDiagram-v2
4040
4141
running --> failed : unhandled StandardError-derived exception
4242
running --> complete : user code finished
43-
running --> stopped : stop
43+
running --> cancelled : cancel
4444
45-
initialized --> stopped : stop
45+
initialized --> cancelled : cancel
4646
4747
failed --> [*]
4848
complete --> [*]
49-
stopped --> [*]
49+
cancelled --> [*]
5050
```
5151

52-
Tasks are created in the `initialized` state, and are run by the reactor. During the execution, a task can either `complete` successfully, become `failed` with an unhandled `StandardError`-derived exception, or be explicitly `stopped`. In all of these cases, you can wait for a task to complete by using {ruby Async::Task#wait}.
52+
Tasks are created in the `initialized` state, and are run by the reactor. During the execution, a task can either `complete` successfully, become `failed` with an unhandled `StandardError`-derived exception, or be explicitly `cancelled`. In all of these cases, you can wait for a task to complete by using {ruby Async::Task#wait}.
5353

5454
1. In the case the task successfully completed, the result will be whatever value was generated by the last expression in the task.
5555
2. In the case the task failed with an unhandled `StandardError`-derived exception, waiting on the task will re-raise the exception.
56-
3. In the case the task was stopped, the result will be `nil`.
56+
3. In the case the task was cancelled, the result will be `nil`.
5757

5858
## Starting A Task
5959

@@ -175,8 +175,8 @@ Async do
175175
break if done.size >= 2
176176
end
177177
ensure
178-
# The remainder of the tasks will be stopped:
179-
barrier.stop
178+
# The remainder of the tasks will be cancelled:
179+
barrier.cancel
180180
end
181181
end
182182
```
@@ -199,18 +199,18 @@ begin
199199
# Wait until all jobs are done:
200200
barrier.wait
201201
ensure
202-
# Stop any remaining jobs:
203-
barrier.stop
202+
# Cancel any remaining jobs:
203+
barrier.cancel
204204
end
205205
~~~
206206

207-
## Stopping a Task
207+
## Cancelling a Task
208208

209209
When a task completes execution, it will enter the `complete` state (or the `failed` state if it raises an unhandled exception).
210210

211-
There are various situations where you may want to stop a task ({ruby Async::Task#stop}) before it completes. The most common case is shutting down a server. A more complex example is this: you may fan out multiple (10s, 100s) of requests, wait for a subset to complete (e.g. the first 5 or all those that complete within a given deadline), and then stop (terminate/cancel) the remaining operations.
211+
There are various situations where you may want to cancel a task ({ruby Async::Task#cancel}) before it completes. The most common case is shutting down a server. A more complex example is this: you may fan out multiple (10s, 100s) of requests, wait for a subset to complete (e.g. the first 5 or all those that complete within a given deadline), and then cancel the remaining operations.
212212

213-
Using the above program as an example, let's stop all the tasks just after the first one completes.
213+
Using the above program as an example, let's cancel all the tasks just after the first one completes.
214214

215215
```ruby
216216
Async do
@@ -221,14 +221,14 @@ Async do
221221
end
222222
end
223223

224-
# Stop all the above tasks:
225-
tasks.each(&:stop)
224+
# Cancel all the above tasks:
225+
tasks.each(&:cancel)
226226
end
227227
```
228228

229-
### Stopping all Tasks held in a Barrier
229+
### Cancelling all Tasks held in a Barrier
230230

231-
To stop (terminate/cancel) all the tasks held in a barrier:
231+
To cancel all the tasks held in a barrier:
232232

233233
```ruby
234234
barrier = Async::Barrier.new
@@ -241,11 +241,11 @@ Async do
241241
end
242242
end
243243

244-
barrier.stop
244+
barrier.cancel
245245
end
246246
```
247247

248-
Unless your tasks all rescue and suppresses `StandardError`-derived exceptions, be sure to call ({ruby Async::Barrier#stop}) to stop the remaining tasks:
248+
Unless your tasks all rescue and suppresses `StandardError`-derived exceptions, be sure to call ({ruby Async::Barrier#cancel}) to cancel the remaining tasks:
249249

250250
```ruby
251251
barrier = Async::Barrier.new
@@ -261,7 +261,7 @@ Async do
261261
begin
262262
barrier.wait
263263
ensure
264-
barrier.stop
264+
barrier.cancel
265265
end
266266
end
267267
```
@@ -273,10 +273,10 @@ In order to ensure your resources are cleaned up correctly, make sure you wrap r
273273
~~~ ruby
274274
Async do
275275
begin
276-
socket = connect(remote_address) # May raise Async::Stop
276+
socket = connect(remote_address) # May raise Async::Cancel
277277

278-
socket.write(...) # May raise Async::Stop
279-
socket.read(...) # May raise Async::Stop
278+
socket.write(...) # May raise Async::Cancel
279+
socket.read(...) # May raise Async::Cancel
280280
ensure
281281
socket.close if socket
282282
end
@@ -398,9 +398,9 @@ end
398398

399399
Transient tasks are similar to normal tasks, except for the following differences:
400400

401-
1. They are not considered by {ruby Async::Task#finished?}, so they will not keep the reactor alive. Instead, they are stopped (with a {ruby Async::Stop} exception) when all other (non-transient) tasks are finished.
401+
1. They are not considered by {ruby Async::Task#finished?}, so they will not keep the reactor alive. Instead, they are cancelled (with a {ruby Async::Cancel} exception) when all other (non-transient) tasks are finished.
402402
2. As soon as a parent task is finished, any transient child tasks will be moved up to be children of the parent's parent. This ensures that they never keep a sub-tree alive.
403-
3. Similarly, if you `stop` a task, any transient child tasks will be moved up the tree as above rather than being stopped.
403+
3. Similarly, if you `cancel` a task, any transient child tasks will be moved up the tree as above rather than being cancelled.
404404

405405
The purpose of transient tasks is when a task is an implementation detail of an object or instance, rather than a concurrency process. Some examples of transient tasks:
406406

@@ -439,7 +439,7 @@ class TimeStringCache
439439
sleep(1)
440440
end
441441
ensure
442-
# When the reactor terminates all tasks, `Async::Stop` will be raised from `sleep` and this code will be invoked. By clearing `@refresh`, we ensure that the task will be recreated if needed again:
442+
# When the reactor terminates all tasks, `Async::Cancel` will be raised from `sleep` and this code will be invoked. By clearing `@refresh`, we ensure that the task will be recreated if needed again:
443443
@refresh = nil
444444
end
445445
end

0 commit comments

Comments
 (0)