Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101812 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3307 invoked from network); 8 Feb 2018 22:22:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2018 22:22:55 -0000 Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.163 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.163 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.163] ([81.169.146.163:14843] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2E/22-21403-DBDCC7A5 for ; Thu, 08 Feb 2018 17:22:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1518128571; s=strato-dkim-0002; d=kelunik.com; h=Content-Type:Cc:To:Subject:Message-ID:Date:From:References: In-Reply-To:X-RZG-CLASS-ID:X-RZG-AUTH; bh=hWzjbmNO0CWlay7SMaoxVsIiTX07GRtIQRXaaeYPp1o=; b=qGEtS8p3Au+7k5M7CBXhdtAaChVgq3xW1+ZrmN1BeD/OFJSWwZVJVUhVrgjNNs8Csy 9I1FBVbdgWMUlU7wK7AiFfA6/lErEMQD/vFXD0ZyW3rmxOX8FDAzP2kncOHIlMFYC7ow 3itTEq6dbXS0g/EgiciFTKchsLxs7C+A119bZtZMrEqHLzOLugSArg1bk+ux0c683DoG mUUQHMi2u2d/AbY41K87kK7DmurI3GzWlKf2W3u4nt9aurvLvX74trfk4P8ECKR5uamA SsyyQK4Akq1vvx37wHSlBKerZjy9WFNRhb/BCLjrxl58zlkW2axApOJnyKcyp6B6PsoZ HuEQ== X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mlsGbEv0XHBzMIJSS+jKTzde5mDb8Db2nURiq+cA== X-RZG-CLASS-ID: mo00 Received: by mail-yw0-f169.google.com with SMTP id b129so3782570ywa.8 for ; Thu, 08 Feb 2018 14:22:50 -0800 (PST) X-Gm-Message-State: APf1xPAFj9a8XDp3g/WAD/cr/pfuNAAEidLlvB3iAJeZ4sCfyCOTtDmq kfa1q2kO2cstLWXtYdt+GiL5JGeCQw1f+t85MuM= X-Google-Smtp-Source: AH8x226Nl6fuZbzVncNDQmIMBP9XOlhsHC/5nqQsnWd7QX4qWoWJcw4NYcnS5Ga7KPUwplEOZ8kBrJEs8/jP496yO/A= X-Received: by 10.129.179.7 with SMTP id r7mr547516ywh.191.1518128570139; Thu, 08 Feb 2018 14:22:50 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.182.201 with HTTP; Thu, 8 Feb 2018 14:22:49 -0800 (PST) In-Reply-To: References: <76EBF900-3BE8-4B60-9422-880A9754FCC4@lvht.net> <0DDFDACA-6322-461C-9D57-215E8C7D9CD0@trowski.com> Date: Thu, 8 Feb 2018 23:22:49 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Haitao Lv Cc: Aaron Piotrowski , PHP Internals Content-Type: multipart/alternative; boundary="94eb2c146be2258e300564bada47" Subject: Re: [PHP-DEV] [RFC] Fiber support (again) From: me@kelunik.com (Niklas Keller) --94eb2c146be2258e300564bada47 Content-Type: text/plain; charset="UTF-8" > > > - 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() > > Offering methods like Fiber::alive, Fiber::running makes no difference to > check the Fiber::status() return value. This is just a style issue. And as > a language feature, > Fiber only offer the essential API and let other works to the user land. The language should offer a sane API, not the absolute minimum required to work for these things. > > - What about throwing exceptions into a fiber? > > Currently does not support throw exception into the fiber. User land code > could check > the value of Fiber::yield and throw exception themselves. The Ruby's Fiber > and Lua's > coroutine also does not support such api as well. And throw the exception where? That means async code with fibers can't really handle errors? > > > > > - 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). > > All Fiber created with a suspended status. So make resume to do both the > init and resume > do make sense. > It does't make sense to me. Reading the example in the README and understanding why the first resume() takes two arguments instead of one took me quite some minutes. > Please see Ruby Fiber API https://ruby-doc.org/core-2.2.0/Fiber.html. > > > > > - What happens if the sub1() function in the RFC is invoked outside of a > fiber? > > You will get a Fatal Error like > Fatal error: Uncaught Error: Cannot call Fiber::yield out of 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. > > Wishing this to be accepted by the community in the PHP 7.3, so no keyword > is accepted. > And if the community cannot accept, the Fiber can be still distributed as > a standalone > extension. So we cannot depend on a new keyword. Right, if it's a standalone extension it can't use a new keyword, but as a language feature it totally can. Looking at the current README, there are two issues that must be completely solved IMO before accepting this: > Each Fiber has a separate 4k stack. You can use the fiber.stack_size ini option to change the default stack size. You can also use the second argument of Fiber::__construct to set the stack size on fly. Resizing of the stack should happen automatically, just like generators resize automatically. > Fiber::yield cannot be used in internal callback This also seems problematic and will make fibers quite less useful, especially as these yields can happen anywhere down the stack. Regards, Niklas --94eb2c146be2258e300564bada47--