rbzmq icon indicating copy to clipboard operation
rbzmq copied to clipboard

Yield

Open ghost opened this issue 12 years ago • 2 comments

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

ghost avatar May 14 '12 17:05 ghost

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

bwbuchanan avatar May 15 '12 19:05 bwbuchanan

Yes, sorry, will resubmit tomorrow.

On Tue, May 15, 2012 at 3:46 PM, Brian Buchanan < [email protected]

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

ghost avatar May 15 '12 19:05 ghost