Method: Concurrent::Async#init_mutex

Defined in:
lib/concurrent/async.rb

#init_mutexObject

Note:

This method must be called from the constructor of the including class or explicitly by the caller prior to calling any other methods. This is the only way thread-safe initialization can be guaranteed.

Initialize the internal serializer and other synchronization objects. This method must be called from the constructor of the including class or explicitly by the caller prior to calling any other methods. If init_mutex is not called explicitly the async/await/executor methods will raize a Concurrent::InitializationError. This is the only way thread-safe initialization can be guaranteed.

Raises:

Since:

  • 0.6.0



195
196
197
198
199
200
201
202
203
204
# File 'lib/concurrent/async.rb', line 195

def init_mutex
  raise InitializationError.new('#init_mutex was already called') if @__async_initialized__
  @__async_initialized__ = true
  serializer = Concurrent::SerializedExecution.new
  @__async_executor__ = Delay.new{ Concurrent.configuration.global_operation_pool }
  @__await_delegator__ = Delay.new{ AsyncDelegator.new(
    self, Delay.new{ Concurrent::ImmediateExecutor.new }, serializer, true) }
  @__async_delegator__ = Delay.new{ AsyncDelegator.new(
    self, @__async_executor__, serializer, false) }
end