Module: Karafka::Helpers::Async
- Included in:
- Connection::Listener, Processing::Worker
- Defined in:
- lib/karafka/helpers/async.rb
Overview
Note:
Thread running code needs to manage it’s own exceptions. If they leak out, they will abort thread on exception.
Allows a given class to run async in a separate thread. Provides also few methods we may want to use to control the underlying thread
Class Method Summary collapse
-
.included(base) ⇒ Object
Adds forwardable to redirect thread-based control methods to the underlying thread that runs the async operations.
Instance Method Summary collapse
-
#async_call ⇒ Object
Runs the ‘#call` method in a new thread.
Class Method Details
.included(base) ⇒ Object
Adds forwardable to redirect thread-based control methods to the underlying thread that runs the async operations
16 17 18 19 20 |
# File 'lib/karafka/helpers/async.rb', line 16 def included(base) base.extend ::Forwardable base.def_delegators :@thread, :join, :terminate, :alive? end |
Instance Method Details
#async_call ⇒ Object
Runs the ‘#call` method in a new thread
24 25 26 27 28 29 30 |
# File 'lib/karafka/helpers/async.rb', line 24 def async_call @thread = Thread.new do Thread.current.abort_on_exception = true call end end |