Skip to content

Commit

Permalink
run handlers loop in a single async task
Browse files Browse the repository at this point in the history
  • Loading branch information
milestruecar committed Jun 30, 2023
1 parent 5e878ab commit f3c1af0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/slack/real_time/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(options = {})
@token ||= Slack.config.token
@logger ||= (Slack::Config.logger || Slack::Logger.default)
@web_client = Slack::Web::Client.new(token: token, logger: logger)
logger.info(to_s) {}
end

[:self, :team, *Stores::Base::CACHES].each do |store_method|
Expand Down Expand Up @@ -234,8 +235,10 @@ def dispatch(event)

def run_handlers(type, data)
handlers = store.class.events[type.to_s]
handlers.each do |handler|
Async.run { store.instance_exec(data, self, &handler) }
Async.run do
handlers.each do |handler|
store.instance_exec(data, self, &handler)
end
end
rescue StandardError => e
logger.error("#{self}##{__method__}") { e }
Expand Down
2 changes: 1 addition & 1 deletion lib/slack/real_time/stores/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def team
end

if caches.include?(:public_channels) || caches.include?(:private_channels) ||
caches.include?(:ims) || caches.include?(:mpims)
caches.include?(:ims) || caches.include?(:mpims)
types = CONVERSATION_TYPES.slice(*caches).values.join(',')
client.web_client.conversations_list(types: types) do |conversations|
conversations.channels.each do |channel_data|
Expand Down

0 comments on commit f3c1af0

Please sign in to comment.