From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 93A6F1F8C6 for ; Mon, 13 Sep 2021 02:32:46 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A3AA3120A66; Mon, 13 Sep 2021 11:31:22 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 9E05F120A5C for ; Mon, 13 Sep 2021 11:31:20 +0900 (JST) Received: by filterdrecv-7bf5c69d5-p7gjg with SMTP id filterdrecv-7bf5c69d5-p7gjg-1-613EB848-3C 2021-09-13 02:32:41.078774933 +0000 UTC m=+965566.062133020 Received: from herokuapp.com (unknown) by geopod-ismtpd-4-2 (SG) with ESMTP id otEtDtk-R8SrRTRLoopKYg for ; Mon, 13 Sep 2021 02:32:40.830 +0000 (UTC) Date: Mon, 13 Sep 2021 02:32:41 +0000 (UTC) From: "tagomoris (Satoshi TAGOMORI)" Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 18162 X-Redmine-Issue-Author: tagomoris X-Redmine-Sender: tagomoris X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 81388 X-SG-EID: =?us-ascii?Q?f07=2FJznobfmetj2dtgpMPitO2F1HBp+4Zdrq+Q0rndmMh+EFepa=2FogMN2Qy9XB?= =?us-ascii?Q?fqkHNYj2FeYFBQIJmbJ93VhD3izZ4SQI6ZoV40v?= =?us-ascii?Q?fcvmIkDOn5IV6+FdZqQovd=2FKyDW12TcV1WtFuV3?= =?us-ascii?Q?kaNZ986LadixilRExN3+04z=2Ff2WOOYhOoQebvVo?= =?us-ascii?Q?ZRWrqvje0JLOmFtGLcsg5V+ElOyPE7S=2FnreSY1g?= =?us-ascii?Q?inUDPc8Veqo3AblEgDF41Dq1YPZJIXpNLt=2Fyqbq?= =?us-ascii?Q?q7hvsVocZg0DNor+Nacgw=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 105212 Subject: [ruby-core:105212] [Ruby master Feature#18162] Shorthand method Proc#isolate to create isolated proc objects X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" 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/