diff options
author | Matthew Draper <matthew@trebex.net> | 2016-01-22 11:13:51 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-01-24 15:52:47 +1030 |
commit | b17a7e4c4daa4ab54223b0c5e2d03b491c070e0e (patch) | |
tree | 10cc764f5c6d2c93ce34a38dd8d0334759544dbe | |
parent | e81bb80cb4214ff795f7a2bb03f699e2a7f7d45a (diff) | |
download | rails-b17a7e4c4daa4ab54223b0c5e2d03b491c070e0e.tar.gz rails-b17a7e4c4daa4ab54223b0c5e2d03b491c070e0e.tar.bz2 rails-b17a7e4c4daa4ab54223b0c5e2d03b491c070e0e.zip |
Add Async and Inline adapters
Just like their ActiveJob equivalents, these only work within the
current process.
-rw-r--r-- | actioncable/lib/action_cable/subscription_adapter/async.rb | 22 | ||||
-rw-r--r-- | actioncable/lib/action_cable/subscription_adapter/inline.rb | 22 |
2 files changed, 44 insertions, 0 deletions
diff --git a/actioncable/lib/action_cable/subscription_adapter/async.rb b/actioncable/lib/action_cable/subscription_adapter/async.rb new file mode 100644 index 0000000000..85d4892e4c --- /dev/null +++ b/actioncable/lib/action_cable/subscription_adapter/async.rb @@ -0,0 +1,22 @@ +require 'action_cable/subscription_adapter/inline' + +module ActionCable + module SubscriptionAdapter + class Async < Inline # :nodoc: + private + def subscriber_map + @subscriber_map ||= AsyncSubscriberMap.new + end + + class AsyncSubscriberMap < SubscriberMap + def add_subscriber(*) + ::EM.next_tick { super } + end + + def invoke_callback(*) + ::EM.next_tick { super } + end + end + end + end +end diff --git a/actioncable/lib/action_cable/subscription_adapter/inline.rb b/actioncable/lib/action_cable/subscription_adapter/inline.rb new file mode 100644 index 0000000000..19747601be --- /dev/null +++ b/actioncable/lib/action_cable/subscription_adapter/inline.rb @@ -0,0 +1,22 @@ +module ActionCable + module SubscriptionAdapter + class Inline < Base # :nodoc: + def broadcast(channel, payload) + subscriber_map.broadcast(channel, payload) + end + + def subscribe(channel, callback, success_callback = nil) + subscriber_map.add_subscriber(channel, callback, success_callback) + end + + def unsubscribe(channel, callback) + subscriber_map.remove_subscriber(channel, callback) + end + + private + def subscriber_map + @subscriber_map ||= SubscriberMap.new + end + end + end +end |