Class: Phronomy::Runtime::DeterministicScheduler::CoopSignal Private

Inherits:
Object
  • Object
show all
Defined in:
lib/phronomy/runtime/deterministic_scheduler.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Scheduler-aware signal for cooperative suspension.

Used by ConcurrencyGate and TaskGroup to suspend a Fiber until a slot or condition becomes available, without blocking the OS thread. All methods must be called from within a Phronomy::Runtime::DeterministicScheduler tick.

Instance Method Summary collapse

Constructor Details

#initialize(scheduler) ⇒ CoopSignal

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CoopSignal.



46
47
48
49
# File 'lib/phronomy/runtime/deterministic_scheduler.rb', line 46

def initialize(scheduler)
  @scheduler = scheduler
  @waiters = []  # Array of Fiber
end

Instance Method Details

#notify_allvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Wakes up all waiting Fibers.



73
74
75
76
# File 'lib/phronomy/runtime/deterministic_scheduler.rb', line 73

def notify_all
  waiters, @waiters = @waiters, []
  waiters.each { |w| @scheduler.enqueue_fiber(-> { w.resume }) }
end

#notify_onevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Wakes up one waiting Fiber.



65
66
67
68
# File 'lib/phronomy/runtime/deterministic_scheduler.rb', line 65

def notify_one
  waiter = @waiters.shift
  @scheduler.enqueue_fiber(-> { waiter.resume }) if waiter
end

#waitvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Suspends the current Fiber until #notify_one or #notify_all fires.



54
55
56
57
58
59
60
# File 'lib/phronomy/runtime/deterministic_scheduler.rb', line 54

def wait
  @waiters << Fiber.current
  # Yield with :cooperative_suspend so step_callable knows not to
  # automatically re-enqueue this Fiber — only an explicit notify call
  # should resume it.
  Fiber.yield(:cooperative_suspend)
end