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: lib/async/barrier.rb
+2-2
Original file line number
Diff line number
Diff line change
@@ -9,11 +9,11 @@
9
9
moduleAsync
10
10
# A general purpose synchronisation primitive, which allows one task to wait for a number of other tasks to complete. It can be used in conjunction with {Semaphore}.
11
11
#
12
-
# @public Since `stable-v1`.
12
+
# @public Since *Async v1*.
13
13
classBarrier
14
14
# Initialize the barrier.
15
15
# @parameter parent [Task | Semaphore | Nil] The parent for holding any children tasks.
Copy file name to clipboardExpand all lines: lib/async/notification.rb
+1-1
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@
7
7
8
8
moduleAsync
9
9
# A synchronization primitive, which allows fibers to wait until a notification is received. Does not block the task which signals the notification. Waiting tasks are resumed on next iteration of the reactor.
10
-
# @public Since `stable-v1`.
10
+
# @public Since *Async v1*.
11
11
classNotification < Condition
12
12
# Signal to a given task that it should resume operations.
# Compute the scheduler load according to the busy and idle times that are updated by the run loop.
55
+
#
55
56
# @returns [Float] The load of the scheduler. 0.0 means no load, 1.0 means fully loaded or over-loaded.
56
57
defload
57
58
total_time=@busy_time + @idle_time
@@ -95,7 +96,7 @@ def terminate
95
96
end
96
97
97
98
# Terminate all child tasks and close the scheduler.
98
-
# @public Since `stable-v1`.
99
+
# @public Since *Async v1*.
99
100
defclose
100
101
self.run_loopdo
101
102
untilself.terminate
@@ -115,7 +116,7 @@ def close
115
116
end
116
117
117
118
# @returns [Boolean] Whether the scheduler has been closed.
118
-
# @public Since `stable-v1`.
119
+
# @public Since *Async v1*.
119
120
defclosed?
120
121
@selector.nil?
121
122
end
@@ -167,6 +168,8 @@ def resume(fiber, *arguments)
167
168
end
168
169
169
170
# Invoked when a fiber tries to perform a blocking operation which cannot continue. A corresponding call {unblock} must be performed to allow this fiber to continue.
171
+
#
172
+
170
173
# @asynchronous May only be called on same thread as fiber scheduler.
# @parameter pid [Integer] The process ID to wait for.
287
334
# @parameter flags [Integer] A bit-mask of flags suitable for `Process::Status.wait`.
288
335
# @returns [Process::Status] A process status instance.
@@ -335,7 +382,10 @@ def process_wait(pid, flags)
335
382
end
336
383
337
384
# Run one iteration of the event loop.
338
-
# Does not handle interrupts.
385
+
#
386
+
# @public Since *Async v1*.
387
+
# @asynchronous Must be invoked from blocking (root) fiber.
388
+
#
339
389
# @parameter timeout [Float | Nil] The maximum timeout, or if nil, indefinite.
340
390
# @returns [Boolean] Whether there is more work to do.
341
391
defrun_once(timeout=nil)
@@ -354,6 +404,7 @@ def run_once(timeout = nil)
354
404
end
355
405
356
406
# Checks and clears the interrupted state of the scheduler.
407
+
#
357
408
# @returns [Boolean] Whether the reactor has been interrupted.
358
409
privatedefinterrupted?
359
410
if@interrupted
@@ -368,7 +419,9 @@ def run_once(timeout = nil)
368
419
returnfalse
369
420
end
370
421
371
-
# Stop all children, including transient children, ignoring any signals.
422
+
# Stop all children, including transient children.
423
+
#
424
+
# @public Since *Async v1*.
372
425
defstop
373
426
@children&.eachdo |child|
374
427
child.stop
@@ -387,6 +440,7 @@ def stop
387
440
end
388
441
end
389
442
rescueInterrupt=>interrupt
443
+
# If an interrupt did occur during an iteration of the event loop, we need to handle it. More specifically, `self.stop` is not safe to interrupt without potentially corrupting the task tree.
# Run the reactor until all tasks are finished. Proxies arguments to {#async} immediately before entering the loop, if a block is provided.
463
+
#
464
+
# Forwards all parameters to {#async} if a block is given.
465
+
#
466
+
# @public Since *Async v1*.
467
+
#
468
+
# @yields {|task| ...} The top level task, if a block is given.
469
+
# @returns [Task] The initial task that was scheduled into the reactor.
409
470
defrun(...)
410
471
Kernel.raiseClosedErrorif@selector.nil?
411
472
@@ -418,30 +479,23 @@ def run(...)
418
479
returninitial_task
419
480
end
420
481
421
-
# Start an asynchronous task within the specified reactor. The task will be
422
-
# executed until the first blocking call, at which point it will yield and
423
-
# and this method will return.
482
+
# Start an asynchronous task within the specified reactor. The task will be executed until the first blocking call, at which point it will yield and and this method will return.
424
483
#
425
-
# This is the main entry point for scheduling asynchronus tasks.
484
+
# @public Since *Async v1*.
485
+
# @asynchronous May context switch immediately to new task.
486
+
# @deprecated Use {#run} or {Task#async} instead.
426
487
#
427
488
# @yields {|task| ...} Executed within the task.
428
489
# @returns [Task] The task that was scheduled into the reactor.
429
-
# @deprecated With no replacement.
430
490
defasync(*arguments, **options, &block)
491
+
# warn "Async::Scheduler#async is deprecated. Use `run` or `Task#async` instead.", uplevel: 1, category: :deprecated
# Invoke the block, but after the specified timeout, raise {TimeoutError} in any currenly blocking operation. If the block runs to completion before the timeout occurs or there are no non-blocking operations after the timeout expires, the code will complete without any exception.
507
+
#
508
+
# @public Since *Async v1*.
509
+
# @asynchronous May raise an exception at any interruption point (e.g. blocking operations).
510
+
#
453
511
# @parameter duration [Numeric] The time in seconds, in which the task should complete.
512
+
# @parameter exception [Class] The exception class to raise.
513
+
# @parameter message [String] The message to pass to the exception.
514
+
# @yields {|duration| ...} The block to execute with a timeout.
# Invoke the block, but after the specified timeout, raise the specified exception with the given message. If the block runs to completion before the timeout occurs or there are no non-blocking operations after the timeout expires, the code will complete without any exception.
530
+
#
531
+
# @public Since *Async v1* and *Ruby v3.1*. May be invoked from `Timeout.timeout`.
532
+
# @asynchronous May raise an exception at any interruption point (e.g. blocking operations).
533
+
#
534
+
# @parameter duration [Numeric] The time in seconds, in which the task should complete.
535
+
# @parameter exception [Class] The exception class to raise.
536
+
# @parameter message [String] The message to pass to the exception.
537
+
# @yields {|duration| ...} The block to execute with a timeout.
0 commit comments