File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -380,6 +380,36 @@ class Ractor
380380 #
381381 def self.shareable? : (untyped obj) -> bool
382382
383+ # <!--
384+ # rdoc-file=ractor.rb
385+ # - Ractor.sharable_proc(self: nil){} -> sharable proc
386+ # -->
387+ # It returns shareable Proc object. The Proc object is shareable and the self in
388+ # a block will be replaced with the value passed via `self:` keyword.
389+ #
390+ # In a shareable Proc, you can not access to the outer variables.
391+ #
392+ # a = 42
393+ # Ractor.shareable_proc{ p a }
394+ # #=> can not isolate a Proc because it accesses outer variables (a). (ArgumentError)
395+ #
396+ # The `self` should be a sharable object
397+ #
398+ # Ractor.shareable_proc(self: self){}
399+ # #=> self should be shareable: main (Ractor::IsolationError)
400+ #
401+ def self.shareable_proc : [T] () { (?) [self : nil ] -> T } -> ^(?) [self : nil ] -> T
402+ | [T, S] (self : S) { (?) [self : S] -> T } -> ^(?) [self : S] -> T
403+
404+ # <!--
405+ # rdoc-file=ractor.rb
406+ # - Ractor.sharable_proc{} -> sharable proc
407+ # -->
408+ # Same as Ractor.sharable_proc, but returns lambda proc.
409+ #
410+ def self.shareable_lambda : [T] () { (?) [self : nil ] -> T } -> ^(?) [self : nil ] -> T
411+ | [T, S] (self : S) { (?) [self : S] -> T } -> ^(?) [self : S] -> T
412+
383413 # <!--
384414 # rdoc-file=ractor.rb
385415 # - Ractor.store_if_absent(key){ init_block }
You can’t perform that action at this time.
0 commit comments