Changeset View
Changeset View
Standalone View
Standalone View
src/future/FutureIterator.php
| Show First 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | while (true) { | ||||
| $future->updateFuture(); | $future->updateFuture(); | ||||
| } | } | ||||
| // Check if any future has resolved or failed. If we have any such | // Check if any future has resolved or failed. If we have any such | ||||
| // futures, we'll return the first one from the iterator. | // futures, we'll return the first one from the iterator. | ||||
| $resolve_key = null; | $resolve_key = null; | ||||
| foreach ($working_set as $future_key => $future) { | foreach ($working_set as $future_key => $future) { | ||||
| if ($future->hasException()) { | if ($future->canResolve()) { | ||||
| $resolve_key = $future_key; | |||||
| break; | |||||
| } | |||||
| if ($future->hasResult()) { | |||||
| $resolve_key = $future_key; | $resolve_key = $future_key; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| // We've found a future to resolve, so we're done here for now. | // We've found a future to resolve, so we're done here for now. | ||||
| if ($resolve_key !== null) { | if ($resolve_key !== null) { | ||||
| ▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | private function moveFutureToWait($future_key) { | ||||
| unset($this->hold[$future_key]); | unset($this->hold[$future_key]); | ||||
| $this->wait[$future_key] = $future_key; | $this->wait[$future_key] = $future_key; | ||||
| } | } | ||||
| private function moveFutureToWork($future_key) { | private function moveFutureToWork($future_key) { | ||||
| unset($this->wait[$future_key]); | unset($this->wait[$future_key]); | ||||
| $this->work[$future_key] = $future_key; | $this->work[$future_key] = $future_key; | ||||
| $this->futures[$future_key]->startFuture(); | $future = $this->futures[$future_key]; | ||||
| if (!$future->getHasFutureStarted()) { | |||||
| $future | |||||
| ->setRaiseExceptionOnStart(false) | |||||
| ->start(); | |||||
| } | |||||
| } | } | ||||
| private function moveFutureToDone($future_key) { | private function moveFutureToDone($future_key) { | ||||
| $this->key = $future_key; | $this->key = $future_key; | ||||
| unset($this->work[$future_key]); | unset($this->work[$future_key]); | ||||
| // Before we return, do another working set update so we start any | // Before we return, do another working set update so we start any | ||||
| // futures that are ready to go as soon as we can. | // futures that are ready to go as soon as we can. | ||||
| $this->updateWorkingSet(); | $this->updateWorkingSet(); | ||||
| $this->futures[$future_key]->endFuture(); | |||||
| } | } | ||||
| /** | /** | ||||
| * Wait for activity on one of several sockets. | * Wait for activity on one of several sockets. | ||||
| * | * | ||||
| * @param list List of sockets expected to become readable. | * @param list List of sockets expected to become readable. | ||||
| * @param list List of sockets expected to become writable. | * @param list List of sockets expected to become writable. | ||||
| * @param float Timeout, in seconds. | * @param float Timeout, in seconds. | ||||
| ▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines | |||||