rfc:fiber
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:fiber [2018/02/08 00:52] – lvht | rfc:fiber [2018/04/13 00:14] – lvht | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2017-09-13 | * Date: 2017-09-13 | ||
* Author: Haitao Lv, i@lvht.net | * Author: Haitao Lv, i@lvht.net | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 16: | Line 16: | ||
===== Proposal ===== | ===== Proposal ===== | ||
==== Why not make it as a Extension? ==== | ==== Why not make it as a Extension? ==== | ||
+ | Fiber need to trace whether we are called in a nested internal call. | ||
+ | |||
==== Implementation ==== | ==== Implementation ==== | ||
+ | Here is the use land API, | ||
<code php> | <code php> | ||
final class Fiber { | final class Fiber { | ||
Line 25: | Line 28: | ||
public const STATUS_DEAD | public const STATUS_DEAD | ||
- | public function __construct(Closure | + | |
+ | * @param callable $callable any php callable to be paused | ||
+ | * @param int $stack_size fiber stack init size | ||
+ | */ | ||
+ | | ||
+ | /** | ||
+ | * pause the current fiber and ~return~ the $arg1 | ||
+ | * as the Fiber:: | ||
+ | */ | ||
public static function yield($arg1) {} | public static function yield($arg1) {} | ||
+ | | ||
+ | /** | ||
+ | * start or resume a fiber. | ||
+ | | ||
+ | * If the fiber is not started, call resume will init | ||
+ | * the $callable with all args. | ||
+ | * | ||
+ | * If the fiber is paused, call resume will send the first arg | ||
+ | * as the last Fiber:: | ||
+ | */ | ||
public function resume($arg1...) {} | public function resume($arg1...) {} | ||
+ | | ||
+ | /** | ||
+ | * throw a exception into the fiber | ||
+ | */ | ||
+ | public function throw(Throwable $e) {} | ||
/** @throws \UnexpectedValueException */ | /** @throws \UnexpectedValueException */ | ||
Line 38: | Line 64: | ||
</ | </ | ||
+ | Here is the usage demo, | ||
<code php> | <code php> | ||
function sub1() | function sub1() | ||
Line 79: | Line 106: | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
- | From Nikita | ||
< | < | ||
</ | </ | ||
- | Fiber does not support yielding during the internal call. Calling Fiber:: | + | Fiber does not support yielding during the internal call. Calling Fiber:: |
+ | |||
+ | < | ||
+ | |||
+ | Offering methods like < | ||
+ | |||
+ | < | ||
+ | |||
+ | The Fiber:: | ||
+ | |||
+ | < | ||
+ | |||
+ | Both Ruby's Fiber and Lua's coroutine using the **resume()** API to **init** and **resume** their coroutine. There is no need to offer a **dedicate init** API. | ||
+ | |||
+ | < | ||
+ | |||
+ | You will get a Fatal Error like | ||
+ | |||
+ | Fatal error: Uncaught Error: Cannot call Fiber:: | ||
+ | |||
+ | < | ||
+ | |||
+ | Introducing new keywords like await/emit does not offer any essential benefit but only cause BC impact. | ||
+ | |||
+ | Both Ruby's Fiber and Lua's coroutine use method to pause and resume their coroutine. There is no need to introduce new keyword. | ||
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
Line 95: | Line 145: | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | coming soon | + | * https:// |
- | + | * < | |
- | * < | + | * < |
+ | * < | ||
+ | * < | ||
===== Implementation ===== | ===== Implementation ===== | ||
Line 112: | Line 164: | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
- | Keep this updated with features that were discussed on the mail lists. | + | * await/async keyword |
+ | * dedicated Fiber::init API |
rfc/fiber.txt · Last modified: 2018/06/12 07:40 by krakjoe