Class: VK::B
Instance Attribute Summary
Attributes inherited from O
Instance Method Summary collapse
Methods inherited from O
Constructor Details
This class inherits a constructor from VK::O
Instance Method Details
#<<(x) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/valkey/objects.rb', line 112 def << x if x.class == String VK.redis.call("PUBLISH", key, JSON.generate({ input: x })) elsif x.class == Array VK.redis.call("PUBLISH", key, JSON.generate({ inputs: x })) elsif x.class == Hash VK.redis.call("PUBLISH", key, JSON.generate(x)) end end |
#on(&b) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/valkey/objects.rb', line 95 def on &b pubsub = VK.redis.pubsub pubsub.call("SUBSCRIBE", key) Process.detach( fork do loop do if m = pubsub.next_event(0) cn, ty, na, id = key.split(":") if m[0] == "message" b.call({ stub: na, object: cn.gsub("-", "::"), type: ty, id: id, event: m[0], data: JSON.parse(m[2]) }) else ap({ stub: na, object: cn.gsub("-", "::"), type: ty, id: id, event: m[0], data: m[2] }) end end end end ); end |