zeromq / rbzmq

Ruby binding for 0MQ
http://www.zeromq.org/bindings:ruby
247 stars 43 forks source link

Yield #20

Open ghost opened 12 years ago

ghost commented 12 years ago

This patch adds yield to block capability for Contexts and Sockets, cleaning up after the interior of the block exits, just like IO.new(). This allows you to write code such as:

#!/usr/bin/env ruby

require 'zmq'

ZMQ::Context.new do |ctx|
  ctx.socket(ZMQ::SUB) do |sock|
    sock.bind('ipc:///tmp/zmq.1')
    sock.setsockopt(ZMQ::SUBSCRIBE, 'sample')
    loop do
      msg = sock.recv
      puts msg
    end
  end
end
bwbuchanan commented 12 years ago

Cool, can you add a commit that updates the docs as well?

ghost commented 12 years ago

Yes, sorry, will resubmit tomorrow.

On Tue, May 15, 2012 at 3:46 PM, Brian Buchanan < reply@reply.github.com

wrote:

Cool, can you add a commit that updates the docs as well?


Reply to this email directly or view it on GitHub: https://github.com/zeromq/rbzmq/pull/20#issuecomment-5725378