Changeset View
Changeset View
Standalone View
Standalone View
src/future/Future.php
| Show All 19 Lines | abstract class Future extends Phobject { | ||||
| * future will not block. | * future will not block. | ||||
| */ | */ | ||||
| abstract public function isReady(); | abstract public function isReady(); | ||||
| /** | /** | ||||
| * Resolve a future and return its result, blocking until the result is ready | * Resolve a future and return its result, blocking until the result is ready | ||||
| * if necessary. | * if necessary. | ||||
| * | * | ||||
| * @param float Optional timeout after which resolution will pause and | * @return wild Future result. | ||||
| * execution will return to the caller. | |||||
| * @return mixed Future result, or null if the timeout is hit. | |||||
| */ | */ | ||||
| public function resolve($timeout = null) { | public function resolve() { | ||||
| $start = microtime(true); | $args = func_get_args(); | ||||
| if (count($args)) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Parameter "timeout" to "Future->resolve()" is no longer '. | |||||
| 'supported. Update the caller so it no longer passes a '. | |||||
| 'timeout.')); | |||||
| } | |||||
| $wait = $this->getDefaultWait(); | $wait = $this->getDefaultWait(); | ||||
| do { | do { | ||||
| $this->checkException(); | $this->checkException(); | ||||
| if ($this->isReady()) { | if ($this->isReady()) { | ||||
| break; | break; | ||||
| } | } | ||||
| $read = $this->getReadSockets(); | $read = $this->getReadSockets(); | ||||
| $write = $this->getWriteSockets(); | $write = $this->getWriteSockets(); | ||||
| if ($timeout !== null) { | |||||
| $elapsed = microtime(true) - $start; | |||||
| if ($elapsed > $timeout) { | |||||
| $this->checkException(); | |||||
| return null; | |||||
| } else { | |||||
| $wait = $timeout - $elapsed; | |||||
| } | |||||
| } | |||||
| if ($read || $write) { | if ($read || $write) { | ||||
| self::waitForSockets($read, $write, $wait); | self::waitForSockets($read, $write, $wait); | ||||
| } | } | ||||
| } while (true); | } while (true); | ||||
| $this->checkException(); | $this->checkException(); | ||||
| return $this->getResult(); | return $this->getResult(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 127 Lines • Show Last 20 Lines | |||||