class SuchPool
Such Pool is the simplest implementation as possible of a Thread pool in ruby. Making possible to schedule and run your operation on background
Constants
- VERSION
Attributes
pool_size[R]
Public Class Methods
new(pool_size: 5)
click to toggle source
# File lib/such_pool.rb, line 9 def initialize(pool_size: 5) @pool_size = pool_size @queue = Queue.new @pool_size.times do Thread.new do loop do lambd = @queue.pop lambd.call end end end end
Public Instance Methods
run_background(&lambd)
click to toggle source
# File lib/such_pool.rb, line 22 def run_background &lambd @queue << lambd end