Class: Grenache::Base
- Inherits:
-
Object
- Object
- Grenache::Base
- Defined in:
- lib/grenache/base.rb
Instance Method Summary collapse
Instance Method Details
#listen(key, port, opts = {}, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/grenache/base.rb', line 3 def listen(key, port, opts={}, &block) EM.defer { @ws = WebsocketServer.new port, &block @ws.start_server } announce(key, port, opts) do |res| puts "#{key} announced #{res}" end end |
#request(key, payload, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/grenache/base.rb', line 14 def request(key, payload, &block) f = Fiber.current lookup key do |services| f.resume services end services = Fiber.yield ws = WebsocketClient.new services.sample ws.sync_send Oj.dump(payload) do |msg| f.resume msg end end |