Module: Fibre

Extended by:
Fibre
Included in:
Fibre
Defined in:
lib/fibre/fiber_pool.rb,
lib/fibre.rb,
lib/fibre/mock.rb,
lib/fibre/scope.rb,
lib/fibre/version.rb,
lib/fibre/fiber_error.rb,
lib/fibre/rack/fiber_pool.rb

Overview

Fiber pool

Example,

using EventObject
pool = Fibre::FiberPool.new(10)
pool.checkout do
  puts "runned in fiber"
end

Defined Under Namespace

Modules: Rack, Synchrony Classes: FiberError, FiberPool, Mock, Scope

Constant Summary collapse

DEFAULT_POOL_SIZE =
50
DEFAULT_POOL_QUEUE_SIZE =
1000
FIBER_POOL_THREADED =
'__fiber_pool'
VERSION =
'1.0.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rootObject

Establish the root fiber



19
20
21
# File 'lib/fibre.rb', line 19

def root
  @root
end

Instance Method Details

#init_pool(*a) ⇒ Object



26
27
28
# File 'lib/fibre.rb', line 26

def init_pool(*a)
  Thread.current[FIBER_POOL_THREADED] = make_pool(*a)
end

#make_pool(pool_size: DEFAULT_POOL_SIZE, pool_queue_size: DEFAULT_POOL_QUEUE_SIZE) ⇒ Object



40
41
42
# File 'lib/fibre.rb', line 40

def make_pool(pool_size: DEFAULT_POOL_SIZE, pool_queue_size: DEFAULT_POOL_QUEUE_SIZE)
  FiberPool.new(pool_size: pool_size, pool_queue_size: pool_queue_size)
end

#poolObject

Auto-initialize at first call and each thread has own fiber pool



31
32
33
# File 'lib/fibre.rb', line 31

def pool
  Thread.current[FIBER_POOL_THREADED] ||= make_pool
end

#resetObject



35
36
37
38
# File 'lib/fibre.rb', line 35

def reset
  Thread.current[FIBER_POOL_THREADED] = nil
  pool
end