Guest User

Untitled

a guest
Jun 12th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.89 KB | None | 0 0
  1. diff --git a/lib/cinch/handler.rb b/lib/cinch/handler.rb
  2. index 41988b2..d673492 100644
  3. --- a/lib/cinch/handler.rb
  4. +++ b/lib/cinch/handler.rb
  5. @@ -74,11 +74,11 @@ module Cinch
  6.      # @param [Message] message Message that caused the invocation
  7.      # @param [Array] captures Capture groups of the pattern that are
  8.      #   being passed as arguments
  9. -    # @return [void]
  10. +    # @return [Thread]
  11.      def call(message, captures, arguments)
  12.        bargs = captures + arguments
  13.  
  14. -      @thread_group.add Thread.new {
  15. +      thread = Thread.new {
  16.          @bot.loggers.debug "[New thread] For #{self}: #{Thread.current} -- #{@thread_group.list.size} in total."
  17.  
  18.          begin
  19. @@ -93,6 +93,9 @@ module Cinch
  20.            @bot.loggers.debug "[Thread done] For #{self}: #{Thread.current} -- #{@thread_group.list.size - 1} remaining."
  21.          end
  22.        }
  23. +
  24. +      @thread_group.add thread
  25. +      thread
  26.      end
  27.  
  28.      # @return [String]
  29. diff --git a/lib/cinch/handler_list.rb b/lib/cinch/handler_list.rb
  30. index ffbd269..8e00cbf 100644
  31. --- a/lib/cinch/handler_list.rb
  32. +++ b/lib/cinch/handler_list.rb
  33. @@ -51,10 +51,11 @@ module Cinch
  34.      #   and attached to the event, or nil.
  35.      # @param [Array] *arguments A list of additional arguments to pass
  36.      #   to event handlers
  37. -    # @return [void]
  38. +    # @return [Set<Thread>]
  39.      def dispatch(event, msg = nil, *arguments)
  40.        if handlers = find(event, msg)
  41.          already_run = Set.new
  42. +        threads = Set.new
  43.          handlers.each do |handler|
  44.            next if already_run.include?(handler.block)
  45.            already_run << handler.block
  46. @@ -66,9 +67,10 @@ module Cinch
  47.              captures = []
  48.            end
  49.  
  50. -          handler.call(msg, captures, arguments)
  51. +          threads << handler.call(msg, captures, arguments)
  52.          end
  53.        end
  54. +      threads
  55.      end
  56.  
  57.      # @yield [handler] Yields all registered handlers
Advertisement
Add Comment
Please, Sign In to add comment