On 31 August 2017 15:28:36 BST, Haitao Lv <i...@lvht.net> wrote: >So I propose to introduce the sackful coroutine, aka Fiber, support for >PHP.
Hi! Is this your own invention, or is the name and semantics based on some existing language or computer science theory? "Fiber" makes me think of strings, rather than coroutines, so maybe I'm missing a key metaphor here. >> <?php >> function foo($a) >> { >> $b = await $a + 1; >> echo $b; >> } Should "await" be "yield" here? If not, what happens if I call foo() without being inside a Fiber? Similarly, if I run bar() and it runs foo(), what result will I get outside a Fiber, since bar() has no yield, so is not itself a generator? >So the Fiber API is a little like the Generator API, but is more simple >yet powerful. So there >is no need to distinct $generator->current(), $generator->send(), and >$generator->getReturn(). I don't really follow how merging the current() and send() methods is related to whether the coroutine was paused further into the stack. Your ->resume() doesn't seem to do anything a normal generator can't, except that the yield is nested deeper. Nor does it seem to replace getReturn() (although I struggled to understand the rationale for that addition at the time, others swore it was necessary). Meanwhile, how does this relate to other ways of combining generators, such as "yield from"? I do struggle with coroutines, so I may be missing something obvious here. Regards, -- Rowan Collins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php