posix_mq RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* POSIX_MQ and EventMachine integration
@ 2010-12-21 11:00 Iñaki Baz Castillo
  2010-12-22 19:36 ` Eric Wong
  0 siblings, 1 reply; 5+ messages in thread
From: Iñaki Baz Castillo @ 2010-12-21 11:00 UTC (permalink / raw)
  To: ruby.posix.mq

Hi, as POSIX_MQ provides #to_io method (IO selectable) it's possible
to integrate it within EventMachine. I paste a working code:

--------------------
require "posix_mq"
require "eventmachine"

module PosixMQ_EM

  def initialize
    @data = ""
  end

  def notify_readable
    begin
      MQ.receive @data
      receive_message @data
    rescue Errno::EAGAIN
      $stderr.puts "ERROR: attemp to read from an empty queue"
    end
  end

  def receive_message(msg)
    puts "INFO: received msg: '#{msg}'"
  end

end


EM.run do
  MQ = POSIX_MQ.new "/some_mq, IO::RDONLY | IO::NONBLOCK
  EM.watch(MQ.to_io, PosixMQ_EM) do |conn|
    conn.notify_readable = true
  end
end
--------------------


It seems to work correctly. Just a question: does the usage of #to_io
decrease performance? any suggestion to improve the above code?

Thanks a lot.


-- 
Iñaki Baz Castillo
<ibc@aliax.net>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-12-23 15:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-21 11:00 POSIX_MQ and EventMachine integration Iñaki Baz Castillo
2010-12-22 19:36 ` Eric Wong
2010-12-23  0:51   ` Iñaki Baz Castillo
2010-12-23  3:52     ` Eric Wong
2010-12-23 15:35       ` Iñaki Baz Castillo

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/ruby_posix_mq.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).