Module: DripDrop::ZMQWritableHandler
- Included in:
- Mongrel2Handler, ZMQPubHandler, ZMQPushHandler, ZMQXRepHandler, ZMQXReqHandler
- Defined in:
- lib/dripdrop/handlers/zeromq.rb
Instance Method Summary collapse
- #initialize(*args) ⇒ Object
- #on_writable(conn) ⇒ Object
-
#send_message(message) ⇒ Object
Sends a message, accepting either a DripDrop::Message, a hash that looks like a DripDrop::Message (has keys :name, :head, :body), or your own custom messages.
Instance Method Details
#initialize(*args) ⇒ Object
55 56 57 58 59 |
# File 'lib/dripdrop/handlers/zeromq.rb', line 55 def initialize(*args) super(*args) @send_queue = [] @send_queue_enabled = false end |
#on_writable(conn) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/dripdrop/handlers/zeromq.rb', line 61 def on_writable(conn) unless @send_queue.empty? = @send_queue.shift conn.send_msg(*) else conn.deregister_writable if @send_queue_enabled end end |
#send_message(message) ⇒ Object
Sends a message, accepting either a DripDrop::Message, a hash that looks like a DripDrop::Message (has keys :name, :head, :body), or your own custom messages. Custom messages should either be a String, or for multipart messages, an Array of String objects.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/dripdrop/handlers/zeromq.rb', line 75 def () = dd_messagify() if .is_a?(DripDrop::Message) @send_queue.push([.encoded]) elsif .class == Array @send_queue.push() else @send_queue.push([]) end self.write_connection.register_writable if @send_queue_enabled EM::next_tick { on_writable(self.write_connection) } end |