123456789_123456789_123456789_123456789_123456789_

Module: ActiveSupport::Ractors

Do not use. This module is for internal use only.

Overview

Shims for Ractor shareability methods so framework code can call them unconditionally regardless of the Ruby version.

Class Attribute Summary

Class Method Summary

Autoload - Extended

Class Attribute Details

.unshareable_proc_action (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/ractors.rb', line 13

attr_accessor :unshareable_proc_action

Class Method Details

.make_shareable(obj, copy: false)

Makes obj Ractor-shareable by delegating to Ractor.make_shareable.

The copy: option is forwarded unchanged. On Ruby versions without Ractor.make_shareable, this shim returns obj unchanged.

See additional method definition at line 48.

[ GitHub ]

  
# File 'activesupport/lib/active_support/ractors.rb', line 80

def make_shareable(...)
  Ractor.make_shareable(...)
end

.shareable?(obj) ⇒ Boolean

Returns whether obj is Ractor-shareable by delegating to Ractor.shareable?.

On Ruby versions without Ractor.shareable?, this shim returns obj unchanged.

See additional method definition at line 57.

[ GitHub ]

  
# File 'activesupport/lib/active_support/ractors.rb', line 84

def shareable?(obj)
  Ractor.shareable?(obj)
end

.shareable_lambda(self: nil, &block)

Returns a Ractor-shareable lambda by delegating to Ractor.shareable_lambda.

The optional self: value is forwarded as the lambda's receiver. On Ruby versions without Ractor.shareable_lambda, this shim returns the block unchanged.

See additional method definition at line 76.

[ GitHub ]

  
# File 'activesupport/lib/active_support/ractors.rb', line 92

def shareable_lambda(...)
  Ractor.shareable_lambda(...)
end

.shareable_proc(self: nil, &block)

Returns a Ractor-shareable proc by delegating to Ractor.shareable_proc.

The optional self: value is forwarded as the proc's receiver. On Ruby versions without Ractor.shareable_proc, this shim returns the block unchanged.

See additional method definition at line 66.

[ GitHub ]

  
# File 'activesupport/lib/active_support/ractors.rb', line 88

def shareable_proc(...)
  Ractor.shareable_proc(...)
end

.try_shareable_proc(proc = nil, &block)

Attempt to make a proc shareable. If successful, a shareable proc is returned. If a Ractor::IsolationError is raised, the outcome will depend on how the user's application configuration:

:raise - The error is raised :warn - A deprecation warning is triggered and the original unshareable proc is returned.

[ GitHub ]

  
# File 'activesupport/lib/active_support/ractors.rb', line 21

def try_shareable_proc(proc = nil, &block)
  proc ||= block
  return proc unless unshareable_proc_action

  shareable_proc(&proc)
rescue Ractor::IsolationError
  case unshareable_proc_action
  when :raise
    raise
  when :warn
    ActiveSupport.deprecator.warn(<<~MSG)
      Rails attempted to make a Proc from your application Ractor shareable but a Ractor
      Isolation error was raised. The proc being returned is not Ractor safe and a runtime
      error may occur anytime during the request lifecycle.

      #{proc.inspect}
    MSG

    proc
  end
end