Class: Farce::Concurrent::ThreadLocalVar

Inherits:
LocalVar
  • Object
show all
Defined in:
lib/farce/concurrent/thread_local_var.rb

Overview

A replacement for concurrent-ruby's Concurrent::ThreadLocalVar May or may not be Ractor-shareable depending on provided default values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Abstract::Value

#blank?, #unwrap

Constructor Details

#initialize(default = nil) ⇒ ThreadLocalVar #initialize { ... } ⇒ ThreadLocalVar

Returns a new instance of ThreadLocalVar.

Overloads:

  • #initialize(default = nil) ⇒ ThreadLocalVar

    Parameters:

    • default (Object) (defaults to: nil) —

      the default value for the thread-local variable

  • #initialize { ... } ⇒ ThreadLocalVar

    Yields:

    • the block to compute the default value for the thread-local variable



25
# File 'lib/farce/concurrent/thread_local_var.rb', line 25

def initialize(...) = super(:thread, ...)

Instance Attribute Details

#value ⇒ Object

Returns the current value of the thread-local variable.

Returns:

  • (Object) —

    the current value of the thread-local variable



19
20
21
22
23
24
25
26
# File 'lib/farce/concurrent/thread_local_var.rb', line 19

class ThreadLocalVar < LocalVar
  # @overload initialize(default = nil)
  #   @param default [Object] the default value for the thread-local variable
  #
  # @overload initialize
  #   @yield the block to compute the default value for the thread-local variable
  def initialize(...) = super(:thread, ...)
end

Instance Method Details

#bind(value) { ... } ⇒ BasicObject

Returns the result of the block.

Parameters:

  • value (Object) —

    the value to bind to the thread-local variable

Yields:

  • the block with the value bound to the thread-local variable

Returns:

  • (BasicObject) —

    the result of the block



19
20
21
22
23
24
25
26
# File 'lib/farce/concurrent/thread_local_var.rb', line 19

class ThreadLocalVar < LocalVar
  # @overload initialize(default = nil)
  #   @param default [Object] the default value for the thread-local variable
  #
  # @overload initialize
  #   @yield the block to compute the default value for the thread-local variable
  def initialize(...) = super(:thread, ...)
end