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:14] – lvht | rfc:fiber [2018/06/10 12:07] – lvht | ||
---|---|---|---|
Line 2: | Line 2: | ||
* Version: 0.1 | * Version: 0.1 | ||
* Date: 2017-09-13 | * Date: 2017-09-13 | ||
- | * Author: Haitao Lv, i@lvht.net | + | * Author: Haitao Lv<i@lvht.net>, Dmitry Stogov< |
- | * 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. | + | Fiber is a major language feature, that allows significant benefits for asynchronous frameworks. Providing it as an optional extension, just doesn' |
==== Implementation ==== | ==== Implementation ==== | ||
- | Here is the use land API, | + | === Proposed |
<code php> | <code php> | ||
final class Fiber { | final class Fiber { | ||
Line 41: | Line 41: | ||
| | ||
/** | /** | ||
- | | + | |
| | ||
* If the fiber is not started, call resume will init | * If the fiber is not started, call resume will init | ||
Line 52: | Line 52: | ||
| | ||
/** | /** | ||
- | | + | |
+ | * | ||
+ | * 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() {} | ||
} | } | ||
</ | </ | ||
- | Here is the usage demo, | + | === Usage Demo === |
<code php> | <code php> | ||
function sub1() | function sub1() | ||
Line 81: | Line 79: | ||
echo $fiber-> | echo $fiber-> | ||
</ | </ | ||
+ | |||
+ | === Implementation Detail === | ||
+ | In our simple implementation, | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 106: | Line 107: | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
- | < | + | < |
- | </ | + | Martin Schröder is working on this at https:// |
- | Fiber does not support yielding during | + | And here is the comparison. |
+ | ^Property^Stackless | ||
+ | |1 Minimum Memory Usage|VM stack only (4 KB)|VM & C stack (4 KB + 4 KB)| | ||
+ | |2 Supported Architecturs|any platform|x86 at this time| | ||
+ | |3 Yield in Internal Function|unsupported|supported| | ||
+ | |4 Yield in Iterator|unsupported|supported| | ||
- | < | + | Stackless |
- | Offering methods like < | + | Native fibers are very platform-dependend |
- | < | + | < |
- | The Fiber:: | + | And as a language feature, |
- | < | + | < |
- | 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. | + | Both Ruby's Fiber and Lua's coroutine using the same **resume()** API to **init** and **resume** their coroutine. |
- | + | ||
- | < | + | |
- | + | ||
- | 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 139: | Line 133: | ||
===== Future Scope ===== | ===== Future Scope ===== | ||
- | This sections details areas where the feature might be improved | + | |
+ | Syntax like async/await can be implemented | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | Simple 50%+1 majority | + | 2/3+1 voting |
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
Line 164: | Line 159: | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
- | * await/async keyword | ||
- | * dedicated Fiber::init API |
rfc/fiber.txt · Last modified: 2018/06/12 07:40 by krakjoe