Method: ZK::Threadpool#defer

Defined in:
lib/zk/threadpool.rb

#defer(callable = nil, &blk) ⇒ Object

Queue an operation to be run on an internal threadpool. You may either provide an object that responds_to?(:call) or pass a block. There is no mechanism for retrieving the result of the operation, it is purely fire-and-forget, so the user is expected to make arrangements for this in their code.

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/zk/threadpool.rb', line 50

def defer(callable=nil, &blk)
  callable ||= blk

  raise ArgumentError, "Argument to Threadpool#defer must respond_to?(:call)" unless callable.respond_to?(:call)

  @mutex.lock
  begin
    @queue << callable
    @cond.broadcast
  ensure
    @mutex.unlock rescue nil
  end

  nil
end