From: "tagomoris (Satoshi TAGOMORI)" Date: 2021-09-13T02:33:31+00:00 Subject: [ruby-core:105213] [Ruby master Feature#18162] Shorthand method Proc#isolate to create isolated proc objects Issue #18162 has been updated by tagomoris (Satoshi TAGOMORI). The related ticket is here about Proc#isolated? https://bugs.ruby-lang.org/issues/18137 ---------------------------------------- Feature #18162: Shorthand method Proc#isolate to create isolated proc objects https://bugs.ruby-lang.org/issues/18162#change-93620 * Author: tagomoris (Satoshi TAGOMORI) * Status: Open * Priority: Normal ---------------------------------------- Currently, isolated proc objects can be created only via Ractor.make_shareable() method. But isolated proc objects are useful for other use-cases too. So I want to propose a new method Proc#isolate to make it isolated. For example, it's useful with async I/O patterns like this: ```ruby x = 1 y = 2 chk1 = ->(async_io){ async_io.write JSON.dump({x:, y:}) }.isolate async_make_checkpoint(&chk1) x = processing_may_fail(x) y = processing_may_fail(y) chk2 = ->(async_io){ async_io.write JSON.dump({x:, y:}) }.isolate async_make_checkpoint(&chk2) # ... ``` In the use-case above, async_make_checkpoint is to create a checkpoint in an async manner to record the (lexical) "current" value of variables. If we can do the thing like above, we'll be able to record how values of x/y are changed (or not changed). In my opinion, we'll have many similar use-cases because Ruby 3.x has the fiber scheduler. And of course, this should be also useful to define shareable methods using Module#define_method. ```ruby x = 1 define_method(:get_x, &->(){ x }.isolate) # is much simpler than below x = 1 getter_x = Ractor.make_shareable(->(){ x }) define_method(:get_x, &getter_x) ``` -- https://bugs.ruby-lang.org/ Unsubscribe: