Class: ZeevexConcurrency::ThreadPool::InlineThreadPool

Inherits:
Object
  • Object
show all
Includes:
Stubs
Defined in:
lib/zeevex_concurrency/thread_pool.rb

Overview

Run job semi-synchronously (on a separate thread, but block on it) We use a separate thread

Instance Method Summary collapse

Methods included from Stubs

#backlog, #busy?, #busy_count, #flush, #free_count, #worker_count

Constructor Details

#initialize(loop = nil) ⇒ InlineThreadPool

Returns a new instance of InlineThreadPool.



100
101
102
# File 'lib/zeevex_concurrency/thread_pool.rb', line 100

def initialize(loop = nil)
  start
end

Instance Method Details

#enqueue(callable = nil, &block) ⇒ Object



116
117
118
119
120
121
122
123
# File 'lib/zeevex_concurrency/thread_pool.rb', line 116

def enqueue(callable = nil, &block)
  raise "Must be started" unless @started
  callable = _check_args(callable, block)
  thr = Thread.new do
    callable.call
  end
  thr.join
end

#joinObject



112
113
114
# File 'lib/zeevex_concurrency/thread_pool.rb', line 112

def join
  true
end

#startObject



104
105
106
# File 'lib/zeevex_concurrency/thread_pool.rb', line 104

def start
  @started = true
end

#stopObject



108
109
110
# File 'lib/zeevex_concurrency/thread_pool.rb', line 108

def stop
  @started = false
end