Class: UringMachine::BlockingOperationThreadPool
- Inherits:
-
Object
- Object
- UringMachine::BlockingOperationThreadPool
- Defined in:
- lib/uringmachine/fiber_scheduler.rb
Overview
Implements a worker thread pool for running blocking operations. Worker threads are started as needed. Worker thread count is limited to the number of CPU cores available.
Instance Method Summary collapse
-
#initialize ⇒ void
constructor
Initializes a new worker pool.
-
#process(machine, job) ⇒ any
Processes a request by submitting it to the job queue and waiting for the return value.
Constructor Details
Instance Method Details
#process(machine, job) ⇒ any
Processes a request by submitting it to the job queue and waiting for the return value. Starts a worker if needed.
31 32 33 34 35 36 37 38 |
# File 'lib/uringmachine/fiber_scheduler.rb', line 31 def process(machine, job) queue = Fiber.current.mailbox if @worker_count == 0 || (@pending_count > 0 && @worker_count < @max_workers) start_worker(machine) end machine.push(@job_queue, [queue, job]) machine.shift(queue) end |