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 { | ||||
| private $hasResult = false; | private $hasResult = false; | ||||
| private $hasStarted = false; | private $hasStarted = false; | ||||
| private $hasEnded = false; | private $hasEnded = false; | ||||
| private $result; | private $result; | ||||
| private $exception; | private $exception; | ||||
| private $futureKey; | private $futureKey; | ||||
| private $serviceProfilerCallID; | private $serviceProfilerCallID; | ||||
| private static $nextKey = 1; | |||||
| /** | /** | ||||
| * 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 212 Lines • ▼ Show 20 Lines | final public function setFutureKey($key) { | ||||
| } | } | ||||
| $this->futureKey = $key; | $this->futureKey = $key; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| final public function getFutureKey() { | final public function getFutureKey() { | ||||
| static $next_key = 1; | |||||
| if ($this->futureKey === null) { | if ($this->futureKey === null) { | ||||
| $this->futureKey = sprintf('Future/%d', $next_key++); | $this->futureKey = sprintf('Future/%d', self::$nextKey++); | ||||
| } | } | ||||
| return $this->futureKey; | return $this->futureKey; | ||||
| } | } | ||||
| } | } | ||||