Class: Farce::ThreadScheduler
- Inherits:
-
Abstract::Scheduler
- Object
- Abstract::Scheduler
- Farce::ThreadScheduler
- Includes:
- Shareable::Immutable, Internal::Inspect
- Defined in:
- lib/farce/thread_scheduler.rb
Overview
A scheduler that starts a new thread for each scheduled task. Executes synchronous tasks inline. Creating an instance starts no threads. Blocks and arguments stay local to the caller. Tasks are not tracked, and closing this stateless scheduler has no effect. Default instances support Marshal. Instances with a custom thread factory reject dumping.
Instance Method Summary collapse
-
#close ⇒ self
Does not wait for or stop task threads.
-
#closed? ⇒ false
This stateless scheduler is always available.
-
#execute(*args, **options) {|*args| ... } ⇒ self
Runs the block on the caller's thread and fiber.
-
#initialize(&factory) ⇒ ThreadScheduler
constructor
A new instance of ThreadScheduler.
- #local?(wait: true) ⇒ true
-
#schedule(*args, **options) {|*args| ... } ⇒ self
Starts a thread in the caller's Ractor, preserving the block and arguments.
-
#state ⇒ Symbol
Always
:running.
Methods included from Shareable
Constructor Details
#initialize(&factory) ⇒ ThreadScheduler
Returns a new instance of ThreadScheduler.
14 15 16 17 |
# File 'lib/farce/thread_scheduler.rb', line 14 def initialize(&factory) @factory = factory super() end |
Instance Method Details
#close ⇒ self
Returns Does not wait for or stop task threads.
58 |
# File 'lib/farce/thread_scheduler.rb', line 58 def close = self |
#closed? ⇒ false
Returns This stateless scheduler is always available.
61 |
# File 'lib/farce/thread_scheduler.rb', line 61 def closed? = false |
#execute(*args, **options) {|*args| ... } ⇒ self
Runs the block on the caller's thread and fiber. Exceptions propagate to the caller.
51 52 53 54 55 |
# File 'lib/farce/thread_scheduler.rb', line 51 def execute(*, **) raise LocalJumpError, "Cannot yield without a block" unless block_given? yield(*) self end |
#local?(wait: true) ⇒ true
68 |
# File 'lib/farce/thread_scheduler.rb', line 68 def local?(wait: true) = true # rubocop:disable Lint/UnusedMethodArgument |
#schedule(*args, **options) {|*args| ... } ⇒ self
Starts a thread in the caller's Ractor, preserving the block and arguments.
38 39 40 41 42 |
# File 'lib/farce/thread_scheduler.rb', line 38 def schedule(*, **, &) raise LocalJumpError, "Cannot schedule without a block" unless block_given? @factory ? @factory.call(*, &) : Thread.new(*, &) self end |
#state ⇒ Symbol
Returns Always :running.
64 |
# File 'lib/farce/thread_scheduler.rb', line 64 def state = :running |