File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -588,6 +588,23 @@ class Ractor
588588 #
589589 def self.shareable? : (untyped obj) -> bool
590590
591+ # <!--
592+ # rdoc-file=ractor.rb
593+ # - Ractor.store_if_absent(key){ init_block }
594+ # -->
595+ # If the correponding value is not set, yield a value with init_block and store
596+ # the value in thread-safe manner. This method returns corresponding stored
597+ # value.
598+ #
599+ # (1..10).map{
600+ # Thread.new(it){|i|
601+ # Ractor.store_if_absent(:s){ f(); i }
602+ # #=> return stored value of key :s
603+ # }
604+ # }.map(&:value).uniq.size #=> 1 and f() is called only once
605+ #
606+ def self.store_if_absent : (Symbol) { () -> untyped } -> untyped
607+
591608 # <!--
592609 # rdoc-file=ractor.rb
593610 # - Ractor.yield(msg, move: false) -> nil
You can’t perform that action at this time.
0 commit comments