Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ractor.store_if_absent #2198

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions core/ractor.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,23 @@ class Ractor
#
def self.shareable?: (untyped obj) -> bool

# <!--
# rdoc-file=ractor.rb
# - Ractor.store_if_absent(key){ init_block }
# -->
# If the correponding value is not set, yield a value with init_block and store
# the value in thread-safe manner. This method returns corresponding stored
# value.
#
# (1..10).map{
# Thread.new(it){|i|
# Ractor.store_if_absent(:s){ f(); i }
# #=> return stored value of key :s
# }
# }.map(&:value).uniq.size #=> 1 and f() is called only once
#
def self.store_if_absent: (Symbol) { () -> untyped } -> untyped

# <!--
# rdoc-file=ractor.rb
# - Ractor.yield(msg, move: false) -> nil
Expand Down
Loading