-
Notifications
You must be signed in to change notification settings - Fork 27
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
Allow properties to be accessed even when the object is moved to another Ractor #29
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely.
Two things:
- could you please use
::Ractor
instead ofRactor
? - could you add a test?
I have made the additions as you suggested. Thanks! |
Great, thank you! |
Thanks! |
…s moved to another Ractor (ruby/ostruct#29) ruby/ostruct@d85639f2f5
setter_proc = Proc.new {|x| @table[name] = x} | ||
if defined?(::Ractor) | ||
::Ractor.make_shareable(getter_proc) | ||
::Ractor.make_shareable(setter_proc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking this would have the side effect of freezing the OpenStruct instance and @table
but actually it does not, which is a CRuby bug: https://bugs.ruby-lang.org/issues/18243
A Ractor should never be able to mutate objects of another Ractor directly of course.
By having the methods defined using shareable Procs, objects that are moved into another Ractor can still use these methods.