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/04/13 00:06] – lvht | rfc:fiber [2018/04/17 22:58] – lvht | ||
---|---|---|---|
Line 16: | Line 16: | ||
===== Proposal ===== | ===== Proposal ===== | ||
==== Why not make it as a Extension? ==== | ==== Why not make it as a Extension? ==== | ||
+ | Fiber is a major language 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 25: | Line 28: | ||
public const STATUS_DEAD | public const STATUS_DEAD | ||
+ | /** | ||
+ | * @param callable $callable any php callable to be paused | ||
+ | * @param int $stack_size fiber stack init size | ||
+ | */ | ||
public function __construct(callable $callable = null, int stack_size = null) {} | public function __construct(callable $callable = null, int stack_size = null) {} | ||
+ | /** | ||
+ | * 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 an exception into the fiber. | ||
+ | | ||
+ | * You code can use try/catch to process error in the | ||
+ | * top level function call. Some framework make heavy | ||
+ | * usage of this feature. | ||
+ | */ | ||
public function throw(Throwable $e) {} | public function throw(Throwable $e) {} | ||
- | |||
- | /** @throws \UnexpectedValueException */ | ||
- | public function __wakeup(): void {} | ||
- | |||
- | /** @throws \Error */ | ||
- | private function __clone() {} | ||
} | } | ||
</ | </ | ||
+ | === 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 116: | Line 143: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | Simple 50%+1 majority | + | 2/3+1 voting |
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
Line 138: | Line 165: | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
- | * await/async keyword | ||
- | * dedicated Fiber::init API |
rfc/fiber.txt · Last modified: 2018/06/12 07:40 by krakjoe