From: "tagomoris (Satoshi TAGOMORI)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:105212] [Ruby master Feature#18162] Shorthand method Proc#isolate to create isolated proc objects
Date: Mon, 13 Sep 2021 02:32:41 +0000 (UTC) [thread overview]
Message-ID: <redmine.issue-18162.20210913023240.1855@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18162.20210913023240.1855@ruby-lang.org
Issue #18162 has been reported by tagomoris (Satoshi TAGOMORI).
----------------------------------------
Feature #18162: Shorthand method Proc#isolate to create isolated proc objects
https://bugs.ruby-lang.org/issues/18162
* 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/
next parent reply other threads:[~2021-09-13 2:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-13 2:32 tagomoris (Satoshi TAGOMORI) [this message]
2021-09-13 2:33 ` [ruby-core:105213] [Ruby master Feature#18162] Shorthand method Proc#isolate to create isolated proc objects tagomoris (Satoshi TAGOMORI)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-18162.20210913023240.1855@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).