Changeset View
Changeset View
Standalone View
Standalone View
src/future/Future.php
| <?php | <?php | ||||
| /** | /** | ||||
| * A 'future' or 'promise' is an object which represents the result of some | * A 'future' or 'promise' is an object which represents the result of some | ||||
| * pending computation. For a more complete overview of futures, see | * pending computation. For a more complete overview of futures, see | ||||
| * @{article:Using Futures}. | * @{article:Using Futures}. | ||||
| */ | */ | ||||
| abstract class Future extends Phobject { | abstract class Future extends Phobject { | ||||
| protected $result; | private $hasResult = false; | ||||
| private $result; | |||||
| protected $exception; | protected $exception; | ||||
| /** | /** | ||||
| * Is this future's process complete? Specifically, can this future be | * Is this future's process complete? Specifically, can this future be | ||||
| * resolved without blocking? | * resolved without blocking? | ||||
| * | * | ||||
| * @return bool If true, the external process is complete and resolving this | * @return bool If true, the external process is complete and resolving this | ||||
| * future will not block. | * future will not block. | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | abstract class Future extends Phobject { | ||||
| * @return list A list of sockets which we expect to become writable. | * @return list A list of sockets which we expect to become writable. | ||||
| */ | */ | ||||
| public function getWriteSockets() { | public function getWriteSockets() { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| /** | /** | ||||
| * Retrieve the final result of the future. This method will be called after | |||||
| * the future is ready (as per @{method:isReady}) but before results are | |||||
| * passed back to the caller. The major use of this function is that you can | |||||
| * override it in subclasses to do postprocessing or error checking, which is | |||||
| * particularly useful if building application-specific futures on top of | |||||
| * primitive transport futures (like @{class:CurlFuture} and | |||||
| * @{class:ExecFuture}) which can make it tricky to hook this logic into the | |||||
| * main pipeline. | |||||
| * | |||||
| * @return mixed Final resolution of this future. | |||||
| */ | |||||
| protected function getResult() { | |||||
| return $this->result; | |||||
| } | |||||
| /** | |||||
| * Default amount of time to wait on stream select for this future. Normally | * Default amount of time to wait on stream select for this future. Normally | ||||
| * 1 second is fine, but if the future has a timeout sooner than that it | * 1 second is fine, but if the future has a timeout sooner than that it | ||||
| * should return the amount of time left before the timeout. | * should return the amount of time left before the timeout. | ||||
| */ | */ | ||||
| public function getDefaultWait() { | public function getDefaultWait() { | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| public function start() { | public function start() { | ||||
| $this->isReady(); | $this->isReady(); | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | |||||
| * Retrieve the final result of the future. | |||||
| * | |||||
| * @return wild Final resolution of this future. | |||||
| */ | |||||
| final protected function getResult() { | |||||
artms: This break drydock test runs, see https://secure.phabricator.com/harbormaster/build/32983/ | |||||
Not Done Inline ActionsPHP Fatal error: Cannot override final method Future::getResult() in /core/data/drydock/workingcopy-75/repo/phabricator/src/applications/harbormaster/future/HarbormasterExecFuture.php on line 50 artms: ```
PHP Fatal error: Cannot override final method Future::getResult() in… | |||||
| if (!$this->hasResult()) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Future has not yet resolved. Resolve futures before retrieving '. | |||||
| 'results.')); | |||||
| } | |||||
| return $this->result; | |||||
| } | |||||
| final protected function setResult($result) { | |||||
| if ($this->hasResult()) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Future has already resolved. Futures may not resolve more than '. | |||||
| 'once.')); | |||||
| } | |||||
| $this->hasResult = true; | |||||
| $this->result = $result; | |||||
| return $this; | |||||
| } | |||||
| final protected function hasResult() { | |||||
| return $this->hasResult; | |||||
| } | |||||
| } | } | ||||
This break drydock test runs, see https://secure.phabricator.com/harbormaster/build/32983/