Page MenuHomePhabricator

D9115.diff
No OneTemporary

D9115.diff

diff --git a/src/future/FutureIterator.php b/src/future/FutureIterator.php
--- a/src/future/FutureIterator.php
+++ b/src/future/FutureIterator.php
@@ -182,7 +182,7 @@
$this->isTimeout = false;
$check = $this->getWorkingSet();
- $resolve = null;
+ $resolved = array();
do {
$read_sockets = array();
$write_sockets = array();
@@ -192,13 +192,11 @@
$future = $this->futures[$key];
try {
if ($future->getException()) {
- $resolve = $wait;
+ $resolved[] = $wait;
continue;
}
if ($future->isReady()) {
- if ($resolve === null) {
- $resolve = $wait;
- }
+ $resolved[] = $wait;
continue;
}
@@ -228,11 +226,11 @@
}
} catch (Exception $ex) {
$this->futures[$key]->setException($ex);
- $resolve = $wait;
- break;
+ $resolved[] = $wait;
+ continue;
}
}
- if ($resolve === null) {
+ if (count($resolved) === 0) {
// Check for a setUpdateInterval() timeout.
if ($timeout !== null) {
@@ -251,11 +249,18 @@
usleep(1000);
}
}
- } while ($resolve === null);
-
+ } while (count($resolved) === 0);
+
+ // Select the first resolved future.
+ $resolve = $resolved[0];
+
$this->key = $this->wait[$resolve];
unset($this->wait[$resolve]);
- $this->updateWorkingSet();
+
+ // Pass the resolved list in so we can skip over
+ // the resolved futures when deciding to start new
+ // ones (when a limit is applied).
+ $this->updateWorkingSet($resolved);
}
/**
@@ -306,22 +311,36 @@
/**
* @task internal
*/
- protected function updateWorkingSet() {
+ protected function updateWorkingSet($resolved = array()) {
if (!$this->limit) {
return;
}
-
- $old = $this->work;
- $this->work = array_slice($this->wait, 0, $this->limit, true);
-
- // If we're using a limit, our futures are sleeping and need to be polled
- // to begin execution, so poll any futures which weren't in our working set
- // before.
- foreach ($this->work as $work => $key) {
- if (!isset($old[$work])) {
- $this->futures[$key]->isReady();
+
+ // Our new working set will be a combination of the currently
+ // resolved futures and the new futures we're starting.
+ $work = array();
+ $count = 0;
+
+ foreach ($this->wait as $wait => $key) {
+ if ($count >= $this->limit) {
+ break;
+ }
+
+ if (!array_key_exists($wait, $resolved)) {
+ if (!$this->futures[$key]->isReady()) {
+ $count++;
+ }
+ $work[$wait] = $key;
+ }
+ }
+
+ foreach ($resolved as $wait) {
+ if (array_key_exists($wait, $this->wait)) {
+ $work[$wait] = $this->wait[$wait];
}
}
+
+ $this->work = $work;
}
}

File Metadata

Mime Type
text/plain
Expires
Fri, Aug 1, 3:11 PM (4 d, 22 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
8800877
Default Alt Text
D9115.diff (2 KB)

Event Timeline