Class: Farce::Concurrent::FiberLocalVar

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

Overview

A replacement for concurrent-ruby's Concurrent::FiberLocalVar 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) ⇒ FiberLocalVar #initialize { ... } ⇒ FiberLocalVar

Returns a new instance of FiberLocalVar.

Overloads:

  • #initialize(default = nil) ⇒ FiberLocalVar

    Parameters:

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

      the default value for the fiber-local variable

  • #initialize { ... } ⇒ FiberLocalVar

    Yields:

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



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

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

Instance Attribute Details

#value ⇒ Object

Returns the current value of the fiber-local variable.

Returns:

  • (Object) —

    the current value of the fiber-local variable



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

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

Instance Method Details

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

Returns the result of the block.

Parameters:

  • value (Object) —

    the value to bind to the fiber-local variable

Yields:

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

Returns:

  • (BasicObject) —

    the result of the block



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

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