Module: Ferrum::Utils::Thread

Defined in:
lib/ferrum/utils/thread.rb

Overview

A helper for spawning threads with consistent exception-handling behavior (abort-on-exception and report-on-exception).

Class Method Summary collapse

Class Method Details

.spawn(abort_on_exception: false) ⇒ Thread

Spawns a new thread running the given block.

Parameters:

  • abort_on_exception (Boolean) (defaults to: false) —

    Whether the thread aborts the process if it raises an unhandled exception. Off by default: an exception in one of Ferrum's own threads reaches the main thread wherever it happens to be, or kills the process outright.

Returns:



22
23
24
25
26
27
28
29
# File 'lib/ferrum/utils/thread.rb', line 22

def spawn(abort_on_exception: false)
  ::Thread.new(abort_on_exception) do |whether_abort_on_exception|
    ::Thread.current.abort_on_exception = whether_abort_on_exception
    ::Thread.current.report_on_exception = true if ::Thread.current.respond_to?(:report_on_exception=)

    yield
  end
end