Module: Moped::Threaded Private

Extended by:
Threaded
Included in:
Threaded
Defined in:
lib/moped/threaded.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.

This module contains logic for easy access to objects that have a lifecycle on the current thread.

Extracted from Mongoid’s Threaded module.

Instance Method Summary collapse

Instance Method Details

#begin(name) ⇒ true

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.

Begin entry into a named thread local stack.

Examples:

Begin entry into the stack.

Threaded.begin(:create)

Parameters:

  • name (String)

    The name of the stack.

Returns:

  • (true)

    True.

Since:

  • 1.0.0



22
23
24
# File 'lib/moped/threaded.rb', line 22

def begin(name)
  stack(name).push(true)
end

#end(name) ⇒ true

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.

Exit from a named thread local stack.

Examples:

Exit from the stack.

Threaded.end(:create)

Parameters:

  • name (Symbol)

    The name of the stack

Returns:

  • (true)

    True.

Since:

  • 1.0.0



50
51
52
# File 'lib/moped/threaded.rb', line 50

def end(name)
  stack(name).pop
end

#executing?(name) ⇒ true

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.

Are in the middle of executing the named stack

Examples:

Are we in the stack execution?

Threaded.executing?(:create)

Parameters:

  • name (Symbol)

    The name of the stack.

Returns:

  • (true)

    If the stack is being executed.

Since:

  • 1.0.0



36
37
38
# File 'lib/moped/threaded.rb', line 36

def executing?(name)
  !stack(name).empty?
end

#stack(name) ⇒ Array

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.

Get the named stack.

Examples:

Get a stack by name

Threaded.stack(:create)

Parameters:

  • name (Symbol)

    The name of the stack

Returns:

Since:

  • 1.0.0



64
65
66
67
# File 'lib/moped/threaded.rb', line 64

def stack(name)
  stacks = (Thread.current[:__moped_threaded_stacks__] ||= {})
  stacks[name] ||= []
end