Method: WeChat::Bot::Handler#call

Defined in:
lib/wechat/bot/handler.rb

#call(message, captures, arguments) ⇒ Thread

执行 Handler

Parameters:

  • message (Symbol)
  • captures (String)
  • arguments (Array)

Returns:

  • (Thread)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/wechat/bot/handler.rb', line 51

def call(message, captures, arguments)
  bargs = captures + arguments

  thread = Thread.new {
    @bot.logger.debug "[New thread] For #{self}: #{Thread.current} -- #{@thread_group.list.size} in total."
    begin
      if @execute_in_callback
        @bot.callback.instance_exec(message, *@args, *bargs, &@block)
      else
        @block.call(message, *@args, *bargs)
      end
    rescue => e
      @bot.logger.error "[Thread error] #{e.message} -> #{e.backtrace.join("\n")}"
    ensure
      @bot.logger.debug "[Thread done] For #{self}: #{Thread.current} -- #{@thread_group.list.size - 1} remaining."
    end
  }

  @thread_group.add(thread)
  thread
end