Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Return a list of threads from HandlerList#dispatch #121

Merged
merged 1 commit into from

2 participants

@nickrw

I have a plugin which wants to block on the execution of an event (being used as a hook to trigger other plugins to act). This pull request changes the return values of:

Handler#call: now returns the Thread it added to @thread_group
HandlerList#dispatch: now returns an array of Threads the event started

These methods previously returned void.

This allows this proof-of-concept plugin to run as expected: https://gist.github.com/nickrw/5769705

@nickrw nickrw Have HandlerList#dispatch return an array of threads started by the e…
…vent.

This allows plugins to wait for handler threads to complete, if desired.
62931f9
@dominikh dominikh merged commit 62931f9 into cinchrb:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 12, 2013
  1. @nickrw

    Have HandlerList#dispatch return an array of threads started by the e…

    nickrw authored
    …vent.
    
    This allows plugins to wait for handler threads to complete, if desired.
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 4 deletions.
  1. +5 −2 lib/cinch/handler.rb
  2. +4 −2 lib/cinch/handler_list.rb
View
7 lib/cinch/handler.rb
@@ -74,11 +74,11 @@ def stop
# @param [Message] message Message that caused the invocation
# @param [Array] captures Capture groups of the pattern that are
# being passed as arguments
- # @return [void]
+ # @return [Thread]
def call(message, captures, arguments)
bargs = captures + arguments
- @thread_group.add Thread.new {
+ thread = Thread.new {
@bot.loggers.debug "[New thread] For #{self}: #{Thread.current} -- #{@thread_group.list.size} in total."
begin
@@ -93,6 +93,9 @@ def call(message, captures, arguments)
@bot.loggers.debug "[Thread done] For #{self}: #{Thread.current} -- #{@thread_group.list.size - 1} remaining."
end
}
+
+ @thread_group.add thread
+ thread
end
# @return [String]
View
6 lib/cinch/handler_list.rb
@@ -51,8 +51,9 @@ def find(type, msg = nil)
# and attached to the event, or nil.
# @param [Array] *arguments A list of additional arguments to pass
# to event handlers
- # @return [void]
+ # @return [Array<Thread>]
def dispatch(event, msg = nil, *arguments)
+ threads = Array.new
if handlers = find(event, msg)
already_run = Set.new
handlers.each do |handler|
@@ -66,9 +67,10 @@ def dispatch(event, msg = nil, *arguments)
captures = []
end
- handler.call(msg, captures, arguments)
+ threads << handler.call(msg, captures, arguments)
end
end
+ threads
end
# @yield [handler] Yields all registered handlers
Something went wrong with that request. Please try again.