Class: FFI::Libfuse::JobPool

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi/libfuse/job_pool.rb

Overview

A JobPool is a ThreadPool whose worker threads are consuming from a Queue

Instance Method Summary collapse

Constructor Details

#initialize(**options, &worker) ⇒ JobPool

Create a Job Pool

Parameters:

  • options (Hash<Symbol,Object>)

    @see ThreadPool.new

  • worker (Proc)

    the unit of work that will be yielded the scheduled jobs



13
14
15
16
# File 'lib/ffi/libfuse/job_pool.rb', line 13

def initialize(**options, &worker)
  @jq = Queue.new
  @tp = ThreadPool.new(**options) { (args = @jq.pop) && worker.call(*args) }
end

Instance Method Details

#closeself

Close the JobPool

Returns:

  • (self)


30
31
32
33
# File 'lib/ffi/libfuse/job_pool.rb', line 30

def close
  @jq.close
  self
end

#groupObject

See Also:



48
49
50
# File 'lib/ffi/libfuse/job_pool.rb', line 48

def group
  @tp.group
end

#join(&block) ⇒ self

Join the JobPool

Returns:

  • (self)


37
38
39
40
# File 'lib/ffi/libfuse/job_pool.rb', line 37

def join(&block)
  @tp.join(&block)
  self
end

#listObject

See Also:



43
44
45
# File 'lib/ffi/libfuse/job_pool.rb', line 43

def list
  @tp.list
end

#schedule(*args) ⇒ self Also known as: <<, push

Schedule a job

Parameters:

  • args (Array<Object>)

Returns:

  • (self)


21
22
23
24
# File 'lib/ffi/libfuse/job_pool.rb', line 21

def schedule(*args)
  @jq.push(args)
  self
end