Skip to content

Commit

Permalink
Fix Ractor.store_if_absent
Browse files Browse the repository at this point in the history
It in fact yields `nil`. Added `nil` in block parameter for testing.
  • Loading branch information
soutaro committed Dec 27, 2024
1 parent 91578f0 commit a38168b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/ractor.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ class Ractor
# }
# }.map(&:value).uniq.size #=> 1 and f() is called only once
#
def self.store_if_absent: (Symbol) { () -> untyped } -> untyped
def self.store_if_absent: [A] (Symbol) { (nil) -> A } -> A

# <!--
# rdoc-file=ractor.rb
Expand Down
7 changes: 7 additions & 0 deletions test/stdlib/Ractor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ def test_shareable?
Ractor, :shareable?, []
end

def test_store_if_absent
assert_send_type(
"(Symbol) { (nil) -> true } -> true",
Ractor, :store_if_absent, :test_store_if_absent, &->(_x) { true }
)
end

def test_yield
Ractor.new(Ractor.current) { |r| loop { r.take } }

Expand Down

0 comments on commit a38168b

Please sign in to comment.