Sha256: e443dec74c3927177c32d8685142203466898cb9ccef62091d1a538267acef56

Contents?: true

Size: 749 Bytes

Versions: 28

Compression:

Stored size: 749 Bytes

Contents

# encoding: utf-8

$:.unshift('.')
$:.unshift(File.expand_path(File.dirname(__FILE__)) + '/../lib')
require 'zmq'

ctx = ZMQ::Context.new
pub = ctx.bind(:PUB, 'inproc://example.poller')

subscribers = []

poller = ZMQ::Poller.new

5.times do
  sub = ctx.connect(:SUB, 'inproc://example.poller')
  sub.subscribe("")
  subscribers << sub
  poller.register_readable(sub)
end

puts "[#{subscribers.size}] subscribers registered with the poller"
p subscribers

puts "publisher sends 'test'"
pub.send("test")

puts "poll, timeout 1s"
poller.poll(1)
puts "readable sockets ..."
p poller.readables
puts "writable sockets ..."
p poller.writables

puts "Subscriber sockets can receive without blocking ..."
p subscribers.map{|s| s.recv_nonblock }

ctx.destroy

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
rbczmq-1.7.9 examples/poller.rb
rbczmq-1.7.8 examples/poller.rb
rbczmq-1.7.7 examples/poller.rb
rbczmq-1.7.6 examples/poller.rb
rbczmq-1.7.5 examples/poller.rb
rbczmq-1.7.4 examples/poller.rb
rbczmq-1.7.3 examples/poller.rb
rbczmq-1.7.2 examples/poller.rb
rbczmq-1.7.1 examples/poller.rb
rbczmq-1.7.0 examples/poller.rb
rbczmq-1.6.4 examples/poller.rb
rbczmq-1.6.2 examples/poller.rb
rbczmq-1.6 examples/poller.rb
rbczmq-1.5 examples/poller.rb
rbczmq-1.4 examples/poller.rb
rbczmq-1.3 examples/poller.rb
rbczmq-1.2 examples/poller.rb
rbczmq-1.1 examples/poller.rb
rbczmq-1.0 examples/poller.rb
rbczmq-0.9 examples/poller.rb