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: AS24940 94.130.0.0/16 X-Spam-Status: No, score=-3.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 7DDA51F852 for ; Wed, 21 Dec 2022 13:41:44 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.b="XuHxTu21"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.b="OMQQqZ+1"; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 790847F03B; Wed, 21 Dec 2022 13:41:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1671630092; bh=9HTc/uJoulYTHMD92qE/XW6pU7YjfJb0LELYdkjpHY4=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=XuHxTu21MYOdGuqUj4jOCoVMD4ULUmaQr743/FnafF7TAa80uD9EdnloqijYnUfFT d+AlvIJwU7ssMfQH9+XkOqZvuegsCPdMA3a8hOA7NTL7407nlFB3KY15ms/IGbBWq3 yV5KqOs5+VhwBwgoapgm0hbypYYHqxJVADLPXO/g= Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 8A71A7E655 for ; Wed, 21 Dec 2022 13:41:27 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=OMQQqZ+1; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=M4nSMBXSEKyNmgelxjfb8LjeQje8TIcie2WyV3rqAGo=; b=OMQQqZ+1dCnjNDMWuh1uf5cJ+QRHZQWZKhDMNiX1xC66ZYscS9OW7mNMIuiKGSb2Or03 3oflHCbq7TmkFcf5W+JBqrEinRQgJN34QtjIDuq3lwWMeom/XeqtP+WCX3UNg6JF/muOyp lNe+7pOQg8oErbdTnFmStbLbVb1PBu/AMHFLwcHdlomoSB45yOJWGYXn/Z4WbescGCHmkq 2gwf1rxOx9jMl5mMy+WfzS94h7qaSlWozEydVUe7BzTTUSTZWfoYWSGexGYq5Qc3huOw2D ANQgC17kDRS7N0Ufxn9PmfwNhJJ57O6vKFyApxP3Utxu2ksFFTeQMbaN9vtZyEoQ== Received: by filterdrecv-557d69979-tbkgw with SMTP id filterdrecv-557d69979-tbkgw-1-63A30D04-4A 2022-12-21 13:41:24.903710967 +0000 UTC m=+2903743.712969229 Received: from herokuapp.com (unknown) by geopod-ismtpd-6-5 (SG) with ESMTP id SbbAFsbBQ3ubcyIeAA1xNA for ; Wed, 21 Dec 2022 13:41:24.785 +0000 (UTC) Date: Wed, 21 Dec 2022 13:41:24 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 19078 X-Redmine-Issue-Author: ioquatix X-Redmine-Issue-Assignee: ioquatix X-Redmine-Sender: Eregon 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: 87759 X-SG-EID: =?us-ascii?Q?DvL3W2Xo+Vk=2FeUn3F50L=2FNc8u9NqZCnbE0mXZHiyye4R1YZg=2FtAFc0SAFzpcS=2F?= =?us-ascii?Q?Zcr7BqPN=2FYCcMZBMITNeIci9STxYay0JAJWPbek?= =?us-ascii?Q?rFR+qUrXZaYNdjYHbz5A17XrJYac=2Fjvh+133NbM?= =?us-ascii?Q?=2FGHPt22MkI0h2bNAzhQq5vjV3ACHSSkl=2FygGbha?= =?us-ascii?Q?E4su3qSHA60a4kduxD2ZPlj=2Fi8AA4WNLhHyx9J=2F?= =?us-ascii?Q?Q2rAIzFBk9aWPCN0p=2F=2FGvLz8gH7RsxZhrBhln0M?= =?us-ascii?Q?KDKLKfZ9XbhHcSzkb6Eug=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== Message-ID-Hash: J2KD5DAI2K4M6KVD7MFDNUD43M4XNRZC X-Message-ID-Hash: J2KD5DAI2K4M6KVD7MFDNUD43M4XNRZC X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:111359] [Ruby master Feature#19078] Introduce `Fiber#storage` for inheritable fiber-scoped variables. List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "Eregon (Benoit Daloze) via ruby-core" Cc: "Eregon (Benoit Daloze)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #19078 has been updated by Eregon (Benoit Daloze). A good use-case for `Fiber#storage=`: https://github.com/ruby-concurrency/concurrent-ruby/issues/456#issuecomment-1361325461 ---------------------------------------- Feature #19078: Introduce `Fiber#storage` for inheritable fiber-scoped variables. https://bugs.ruby-lang.org/issues/19078#change-100735 * Author: ioquatix (Samuel Williams) * Status: Closed * Priority: Normal * Assignee: ioquatix (Samuel Williams) ---------------------------------------- Pull Request: https://github.com/ruby/ruby/pull/6612 This is an evolution of the previous ideas: - https://bugs.ruby-lang.org/issues/19058 - https://bugs.ruby-lang.org/issues/19062 This PR introduces fiber scoped variables, and is a solution for problems like . The main interface is: ```ruby Fiber[key] = value Fiber[key] # => value ``` The variables are scoped (local to) a fiber and inherited into child fibers and threads. ```ruby Fiber[:request_id] = SecureRandom.hex(16) Fiber.new do p Fiber[:request_id] # prints the above request id end ``` The fiber scoped variables are stored and can be accessed: ```ruby Fiber.current.storage # => returns a Hash (copy) of the internal storage. Fiber.current.storage= # => assigns a Hash (copy) to the internal storage. ``` Fiber itself has one new keyword argument: ``` Fiber.new(..., storage: hash, false, undef, nil) ``` This can control how the fiber variables are setup in a child context. To minimise the performance overhead of some of the implementation choices, we are also simultaneously implementing . ## Examples ### Request loop ```ruby Thread.new do while request = queue.pop Fiber.new(storage: {id: SecureRandom.hex(16)}) do handle_request.call(request) end end end ``` OR ```ruby Thread.new do while request = queue.pop Fiber.current.storage = {id: SecureRandom.hex(16)} handle_request.call(request) end end ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/