class method · added in Ruby 4.0
Ractor.shareable_proc
[T] () { (?) [self: nil] -> T } -> ^(?) [self: nil] -> T
[T, S] (self: S) { (?) [self: S] -> T } -> ^(?) [self: S] -> T
Ractor.shareable_proc(self: nil){} → shareable proc
ractor.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/ractor.rb, line 667
def self.shareable_proc self: nil
Primitive.attr! :use_block
__builtin_cexpr!(%Q{
ractor_shareable_proc(ec, *LOCAL_PTR(self), false)
})
end
Returns a shareable copy of the given block’s Proc. The value of self in the Proc will be replaced with the value passed via the self: keyword, or nil if not given.
In a shareable Proc, access to any outer variables if prohibited.
Example
a = 42 Ractor.shareable_proc{ p a } #=> can not isolate a Proc because it accesses outer variables (a). (ArgumentError)
The value of self in the Proc must be a shareable object.
Example
Ractor.shareable_proc(self: self){} #=> self should be shareable: main (Ractor::IsolationError)
Ruby version changes
-
4.0
-
Ractor.shareable_procandRactor.shareable_lambdaare introduced to make shareableProcor lambda. [Feature #21550], [Feature #21557]
-