> On Feb 7, 2018, at 7:05 PM, Haitao Lv <i...@lvht.net> wrote: > > Hi internals, > > I propose to introduce the Fiber feature AGAIN. > > 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. > > In this RFC, no new keyword is needed. So it will not break the PHP 7.3 > release. > > Please see the RFC https://wiki.php.net/rfc/fiber > > 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 > > Please offer you comments. > > Thank you. > > --- > Haitao Lv >
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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php