diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-12-22 01:55:15 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-12-22 05:26:32 +0900 |
commit | 35471a948739ca13b85fe900871e081d553f68e6 (patch) | |
tree | 753724336429afca42bdfc8e30befb79548835a2 /bootstraptest/test_ractor.rb | |
parent | 8f2031a06725d32f59e5ecd88ede3f96e8c5e9b1 (diff) |
add Ractor#[]/#[]= for ractor local storage
This API is similar to plain old Thread#[]/Fiber#[] interface
with symbol key.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3962
Diffstat (limited to 'bootstraptest/test_ractor.rb')
-rw-r--r-- | bootstraptest/test_ractor.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index a853e91416..06bd739931 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -1245,6 +1245,20 @@ assert_equal '[:ok, :ok]', %q{ end } +# Ractor-local storage +assert_equal '[nil, "b", "a"]', %q{ + ans = [] + Ractor.current[:key] = 'a' + r = Ractor.new{ + Ractor.yield self[:key] + self[:key] = 'b' + self[:key] + } + ans << r.take + ans << r.take + ans << Ractor.current[:key] +} + ### ### Synchronization tests ### |