Skip to content

Commit 8070d5d

Browse files
committed
Ractor#take and warn
`Ractor#take` was deprecated but some libraries can use it as an alias for `Ractor#value` (i.e., to wait for a Ractor's temrination and retrieve its result). Therefore `Ractor#take` is simply an alias for `Ractor#value`. This method will remain available until the end of August 2025, unless there is further discussion.
1 parent 9fddb8d commit 8070d5d

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

bootstraptest/test_ractor.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,3 +2211,19 @@ def initialize(a)
22112211
Ractor.receive
22122212
}.tally.sort
22132213
}
2214+
2215+
# Ractor#take will warn for compatibility.
2216+
# This method will be removed after 2025/09/01
2217+
assert_equal "2", %q{
2218+
raise "remove Ractor#take and this test" if Time.now > Time.new(2025, 9, 2)
2219+
$VERBOSE = true
2220+
r = Ractor.new{42}
2221+
$msg = []
2222+
def Warning.warn(msg)
2223+
$msg << msg
2224+
end
2225+
r.take
2226+
r.take
2227+
raise unless $msg.all?{/Ractor#take/ =~ it}
2228+
$msg.size
2229+
}

ractor.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,12 @@ def value
575575
__builtin_ractor_value
576576
end
577577

578+
# keep it for compatibility
579+
def take
580+
Kernel.warn("Ractor#take was deprecated and use Ractor#value instead. This method will be removed after the end of Aug 2025", uplevel: 0)
581+
self.value
582+
end
583+
578584
#
579585
# call-seq:
580586
# ractor.monitor(port) -> self

0 commit comments

Comments
 (0)