Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101809 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49496 invoked from network); 8 Feb 2018 04:18:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2018 04:18:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=aaron@trowski.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=aaron@trowski.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain trowski.com designates 199.38.81.6 as permitted sender) X-PHP-List-Original-Sender: aaron@trowski.com X-Host-Fingerprint: 199.38.81.6 mercury.negativeion.net Received: from [199.38.81.6] ([199.38.81.6:63843] helo=mercury.negativeion.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4F/D1-49805-19FCB7A5 for ; Wed, 07 Feb 2018 23:18:25 -0500 Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id AC67156EE88B; Wed, 7 Feb 2018 23:18:22 -0500 (EST) X-Virus-Scanned: amavisd-new at negativeion.net Received: from mercury.negativeion.net ([127.0.0.1]) by localhost (mercury.negativeion.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xzYLyqwQQg1v; Wed, 7 Feb 2018 23:18:21 -0500 (EST) Received: from jupiter.local (unknown [173.225.150.231]) by mercury.negativeion.net (Postfix) with ESMTPSA id CDEC156EE877; Wed, 7 Feb 2018 23:18:21 -0500 (EST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) In-Reply-To: <76EBF900-3BE8-4B60-9422-880A9754FCC4@lvht.net> Date: Wed, 7 Feb 2018 22:18:20 -0600 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <0DDFDACA-6322-461C-9D57-215E8C7D9CD0@trowski.com> References: <76EBF900-3BE8-4B60-9422-880A9754FCC4@lvht.net> To: Haitao Lv X-Mailer: Apple Mail (2.3445.5.20) Subject: Re: [PHP-DEV] [RFC] Fiber support (again) From: aaron@trowski.com (Aaron Piotrowski) > On Feb 7, 2018, at 7:05 PM, Haitao Lv wrote: >=20 > Hi internals, >=20 > I propose to introduce the Fiber feature AGAIN. >=20 > The main purpose of the RFC is to introducing a lightweight stackful = coroutine support for PHP and make it possible to write non-blocking = code in the blocking style. >=20 > In this RFC, no new keyword is needed. So it will not break the PHP = 7.3 release. >=20 > Please see the RFC https://wiki.php.net/rfc/fiber >=20 > Dmitry and I are working on the implementation at = https://github.com/fiberphp/fiber-ext > And a series of usage demo can be found at = https://github.com/fiberphp/fiber-demo >=20 > Please offer you comments. >=20 > Thank you. >=20 > --- > Haitao Lv >=20 Hi Haitao, I'm very excited to see this sort of feature coming to PHP. A couple of questions and thoughts: - How do you determine when a fiber has returned? Looking at the source, = it appears Fiber::status() must be used, comparing against constants. = Separate methods similar to Generator would be better IMO. e.g.: = Fiber::alive(), Fiber::suspended(), Fiber::running() - What about throwing exceptions into a fiber? - Using Fiber::resume() to initialize the fiber and resume feels = awkward. Separate methods again would be better here, perhaps = Fiber::init(...$args) and Fiber::resume($send). - What happens if the sub1() function in the RFC is invoked outside of a = fiber? - I think a keyword here would be beneficial, even if it has a minor BC = impact. Fibers could then be written like generators. `await` or `emit` = as a keyword perhaps? This would be a less verbose API, feel less = magical (a static method call that actually pauses execution feels out = of place), and would allow Fibers to be returned from methods, named = functions, etc with less boilerplate. Thanks to you and Dmitry for working on this! Aaron Piotrowski=