Module: MultiJSON::Concurrency Private

Defined in:
lib/multi_json/concurrency.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Catalog of process-wide mutexes used to serialize MultiJSON’s lazy initializers and adapter swaps. Each mutex protects a distinct piece of mutable state. Callers go through Concurrency.synchronize rather than touching the mutex constants directly so the constants themselves can stay private_constant and the surface of the module is documented in one place.

Class Method Summary collapse

Class Method Details

.synchronize(name) { ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run a block while holding the named mutex

The “name“ symbol must be one of the keys in the internal “MUTEXES“ table; an unknown name raises “KeyError“ so a typo at the call site fails fast instead of silently dropping synchronization on the floor.

Examples:

MultiJSON::Concurrency.synchronize(:adapter) { ... }

Parameters:

  • name (Symbol)

    mutex identifier

Yields:

  • block to execute while holding the mutex

Returns:

  • (Object)

    the block’s return value

Raises:

  • (KeyError)

    when “name“ does not match a known mutex



53
54
55
# File 'lib/multi_json/concurrency.rb', line 53

def self.synchronize(name, &)
  MUTEXES.fetch(name).synchronize(&)
end