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 D95671F8C6 for ; Mon, 13 Sep 2021 02:33:35 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A49C1120A64; Mon, 13 Sep 2021 11:32:12 +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 B901A120A5C for ; Mon, 13 Sep 2021 11:32:10 +0900 (JST) Received: by filterdrecv-75ff7b5ffb-7dt9d with SMTP id filterdrecv-75ff7b5ffb-7dt9d-1-613EB87B-3 2021-09-13 02:33:31.146599416 +0000 UTC m=+965575.020277183 Received: from herokuapp.com (unknown) by geopod-ismtpd-4-2 (SG) with ESMTP id 4LTHkvNUQyyxvV1hnI0yBg for ; Mon, 13 Sep 2021 02:33:30.992 +0000 (UTC) Date: Mon, 13 Sep 2021 02:33:31 +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: 81389 X-SG-EID: =?us-ascii?Q?f07=2FJznobfmetj2dtgpMPitO2F1HBp+4Zdrq+Q0rndmMh+EFepa=2FogMN2Qy9XB?= =?us-ascii?Q?fqkHNYj2FeYFBQIJmbJ93VhD3izZ4SQI6ZoV40v?= =?us-ascii?Q?fcvmIn6LCDI7MbOzzmagqA5+3GanrJZ5AcMLwgY?= =?us-ascii?Q?bG5BG8077Zlx=2FmbIuNgPBFD2iZruiNX0Su1qo7G?= =?us-ascii?Q?0+9DadPxFwSU8jKOh4=2FEcYip8EJbe74ZcUaf6nf?= =?us-ascii?Q?JBHd6TcprO=2FvVOV=2FIoSygCnzresRu4VL23PyCMa?= =?us-ascii?Q?t+PxVDEMwpjVG8a4NqjkA=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 105213 Subject: [ruby-core:105213] [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 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/