Class: Cod::Beanstalk::Service

Inherits:
Service
  • Object
show all
Defined in:
lib/cod/beanstalk/service.rb

Defined Under Namespace

Classes: Client, Control

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from Cod::Service

Instance Method Details

#one(&block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cod/beanstalk/service.rb', line 3

def one(&block)
  @channel.try_get { |(rq, answer_chan), control| 
    result = if block.arity == 2
      block.call(rq, Control.new(control))
    else
      block.call(rq)
    end
    
    unless control.command_given?
      # The only way to respond to the caller is by exiting the block 
      # without giving metacommands.
      answer_chan.put result if answer_chan
    end
  }
end