8000 Add missing documentation for `Async::WorkerPool`. · socketry/async@7b66a3b · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b66a3b

Browse files
committed
Add missing documentation for Async::WorkerPool.
1 parent 37ca738 commit 7b66a3b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/async/worker_pool.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Async
1010
#
1111
# @private
1212
class WorkerPool
13+
# Used to augment the scheduler to add support for blocking operations.
1314
module BlockingOperationWait
1415
# Wait for the given work to be executed.
1516
#
@@ -23,7 +24,11 @@ def blocking_operation_wait(work)
2324
end
2425
end
2526

27+
# Execute the given work in a background thread.
2628
class Promise
29+
# Create a new promise.
30+
#
31+
# @parameter work [Proc] The work to be done.
2732
def initialize(work)
2833
@work = work
2934
@state = :pending
@@ -33,6 +38,7 @@ def initialize(work)
3338
@thread = nil
3439
end
3540

41+
# Execute the work and resolve the promise.
3642
def call
3743
work = nil
3844

@@ -67,6 +73,7 @@ def call
6773
end
6874
end
6975

76+
# Cancel the work and raise an exception in the background thread.
7077
def cancel
7178
return unless @work
7279

@@ -77,6 +84,9 @@ def cancel
7784
end
7885
end
7986

87+
# Wait for the work to be done.
88+
#
89+
# @returns [Object] The result of the work.
8090
def wait
8191
@guard.synchronize do
8292
while @state == :pending
@@ -92,19 +102,22 @@ def wait
92102
end
93103
end
94104

95-
# A handle to the work being done.
105+
# A background worker thread.
96106
class Worker
107+
# Create a new worker.
97108
def initialize
98109
@work = ::Thread::Queue.new
99110
@thread = ::Thread.new(&method(:run))
100111
end
101112

113+
# Execute work until the queue is closed.
102114
def run
103115
while work = @work.pop
104116
work.call
105117
end
106118
end
107119

120+
# Close the worker thread.
108121
def close
109122
if thread = @thread
110123
@thread = nil

0 commit comments

Comments
 (0)
0