File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -1564,6 +1564,24 @@ class C
1564
1564
}.take
1565
1565
}
1566
1566
1567
+ # Ractor-local storage
1568
+ assert_equal '2' , %q{
1569
+ Ractor.new {
1570
+ fails = 0
1571
+ begin
1572
+ Ractor.main[:key] # cannot get ractor local storage from non-main ractor
1573
+ rescue => e
1574
+ fails += 1 if e.message =~ /Cannot get ractor local/
1575
+ end
1576
+ begin
1577
+ Ractor.main[:key] = 'val'
1578
+ rescue => e
1579
+ fails += 1 if e.message =~ /Cannot set ractor local/
1580
+ end
1581
+ fails
1582
+ }.take
1583
+ }
1584
+
1567
1585
###
1568
1586
### Synchronization tests
1569
1587
###
Original file line number Diff line number Diff line change @@ -835,15 +835,21 @@ def self.make_shareable obj, copy: false
835
835
end
836
836
end
837
837
838
- # get a value from ractor-local storage of current Ractor
838
+ # get a value from ractor-local storage for current Ractor
839
839
# Obsolete and use Ractor.[] instead.
840
840
def []( sym )
841
+ if ( self != Ractor . current )
842
+ raise RuntimeError , "Cannot get ractor local storage for non-current ractor"
843
+ end
841
844
Primitive . ractor_local_value ( sym )
842
845
end
843
846
844
- # set a value in ractor-local storage of current Ractor
847
+ # set a value in ractor-local storage for current Ractor
845
848
# Obsolete and use Ractor.[]= instead.
846
849
def []=( sym , val )
850
+ if ( self != Ractor . current )
851
+ raise RuntimeError , "Cannot set ractor local storage for non-current ractor"
852
+ end
847
853
Primitive . ractor_local_value_set ( sym , val )
848
854
end
849
855
You can’t perform that action at this time.
0 commit comments