Initial Commit
Co-authored-by: Subin <subinthattaparambil@gmail.com> Co-authored-by: Manoj <manojmj92@gmail.com> Co-authored-by: Nithin <webofnithin@gmail.com>
This commit is contained in:
11
app/dispatchers/async_dispatcher.rb
Normal file
11
app/dispatchers/async_dispatcher.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class AsyncDispatcher < BaseDispatcher
|
||||
|
||||
def dispatch(event_name, timestamp, data)
|
||||
event_object = Events::Base.new(event_name, timestamp, data)
|
||||
publish(event_object.method_name, event_object)
|
||||
end
|
||||
|
||||
def listeners
|
||||
[ReportingListener.instance, SubscriptionListener.instance]
|
||||
end
|
||||
end
|
||||
12
app/dispatchers/base_dispatcher.rb
Normal file
12
app/dispatchers/base_dispatcher.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class BaseDispatcher
|
||||
|
||||
include Wisper::Publisher
|
||||
|
||||
def listeners
|
||||
[]
|
||||
end
|
||||
|
||||
def load_listeners
|
||||
listeners.each{|listener| subscribe(listener) }
|
||||
end
|
||||
end
|
||||
24
app/dispatchers/dispatcher.rb
Normal file
24
app/dispatchers/dispatcher.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
class Dispatcher
|
||||
include Singleton
|
||||
|
||||
attr_reader :async_dispatcher, :sync_dispatcher
|
||||
|
||||
def self.dispatch(event_name, timestamp, data, async = false)
|
||||
$dispatcher.dispatch(event_name, timestamp, data, async)
|
||||
end
|
||||
|
||||
def initialize
|
||||
@sync_dispatcher = SyncDispatcher.new
|
||||
@async_dispatcher = AsyncDispatcher.new
|
||||
end
|
||||
|
||||
def dispatch(event_name, timestamp, data, async = false)
|
||||
@sync_dispatcher.dispatch(event_name, timestamp, data)
|
||||
@async_dispatcher.dispatch(event_name, timestamp, data)
|
||||
end
|
||||
|
||||
def load_listeners
|
||||
@sync_dispatcher.load_listeners
|
||||
@async_dispatcher.load_listeners
|
||||
end
|
||||
end
|
||||
11
app/dispatchers/sync_dispatcher.rb
Normal file
11
app/dispatchers/sync_dispatcher.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class SyncDispatcher < BaseDispatcher
|
||||
|
||||
def dispatch(event_name, timestamp, data)
|
||||
event_object = Events::Base.new(event_name, timestamp, data)
|
||||
publish(event_object.method_name, event_object)
|
||||
end
|
||||
|
||||
def listeners
|
||||
[PusherListener.instance]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user