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 [2017/09/22 13:28] – external edit 127.0.0.1 | rfc:fiber [2018/04/17 22:57] – 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? ==== | ||
- | ==== How to deal with internal calls? ==== | + | Fibers is a major feature, that allows significant benefits for asynchronous frameworks. Providing it as an optional extension, just doesn' |
==== Implementation ==== | ==== Implementation ==== | ||
+ | === Proposed API === | ||
<code php> | <code php> | ||
final class Fiber { | final class Fiber { | ||
Line 26: | 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...) {} | ||
- | + | | |
- | /** @throws \UnexpectedValueException | + | /** |
- | | + | * Throw an exception into the fiber. |
- | + | * | |
- | /** @throws \Error | + | * You code can use try/catch to process error in the |
- | | + | * top level function |
+ | * usage of this feature. | ||
+ | | ||
+ | | ||
} | } | ||
</ | </ | ||
+ | === Usage Demo === | ||
+ | Here is the usage demo, | ||
<code php> | <code php> | ||
function sub1() | function sub1() | ||
Line 55: | Line 80: | ||
echo $fiber-> | echo $fiber-> | ||
</ | </ | ||
+ | |||
+ | === Implementation Detail === | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 77: | Line 104: | ||
==== php.ini Defaults ==== | ==== php.ini Defaults ==== | ||
- | None | + | - fiber.stack_size default stack size for A fiber |
===== Open Issues ===== | ===== Open Issues ===== | ||
- | Make sure there are no open issues | + | < |
+ | </ | ||
+ | |||
+ | 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 89: | Line 143: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | Simple 50%+1 majority | + | 2/3+1 voting |
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | * [[https:// | + | * https:// |
+ | * < | ||
+ | * <del>[[https:// | ||
+ | * < | ||
+ | * < | ||
===== Implementation ===== | ===== Implementation ===== | ||
Line 107: | Line 165: | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
- | Keep this updated with features that were discussed on the mail lists. |
rfc/fiber.txt · Last modified: 2018/06/12 07:40 by krakjoe