Skip to content

Commit 1819433

Browse files
Better class Task documentation.
1 parent 6aed0d2 commit 1819433

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

lib/async/task.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

lib/async/task.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,32 @@ def initialize(message = "execution expired")
3131
end
3232
end
3333

34+
# Represents a sequential unit of work, defined by a block, which is executed concurrently with other tasks. A task can be in one of the following states: `initialized`, `running`, `completed`, `failed`, `cancelled` or `stopped`.
35+
#
36+
# ```mermaid
37+
# stateDiagram-v2
38+
# [*] --> Initialized
39+
# Initialized --> Running : Run
40+
#
41+
# Running --> Completed : Return Value
42+
# Running --> Failed : Exception
43+
#
44+
# Completed --> [*]
45+
# Failed --> [*]
46+
#
47+
# Running --> Stopped : Stop
48+
# Stopped --> [*]
49+
# Completed --> Stopped : Stop
50+
# Failed --> Stopped : Stop
51+
# Initialized --> Stopped : Stop
52+
# ```
53+
#
54+
# @example Creating a task that sleeps for 1 second.
55+
# require "async"
56+
# Async do |task|
57+
# sleep(1)
58+
# end
59+
#
3460
# @public Since *Async v1*.
3561
class Task < Node
3662
# Raised when a child task is created within a task that has finished execution.

0 commit comments

Comments
 (0)