Module: Listen::Thread

Defined in:
lib/listen/thread.rb

Class Method Summary collapse

Class Method Details

.new(name, &block) ⇒ Object

Creates a new thread with the given name. Any exceptions raised by the thread will be logged with the thread name and complete backtrace. rubocop:disable Style/MultilineBlockChain



13
14
15
16
17
18
19
20
21
22
# File 'lib/listen/thread.rb', line 13

def new(name, &block)
  thread_name = "listen-#{name}"
  caller_stack = caller

  ::Thread.new do
    rescue_and_log(thread_name, caller_stack: caller_stack, &block)
  end.tap do |thread|
    thread.name = thread_name
  end
end

.rescue_and_log(method_name, *args, caller_stack: nil) ⇒ Object

rubocop:enable Style/MultilineBlockChain



25
26
27
28
29
# File 'lib/listen/thread.rb', line 25

def rescue_and_log(method_name, *args, caller_stack: nil)
  yield(*args)
rescue => exception
  _log_exception(exception, method_name, caller_stack: caller_stack)
end