mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42:41 +01:00
Remove the "timeout" parameter from "Future->resolve()"
Summary: Ref T11968. This future-level parameter has no nontrivial callers and makes the "fate of FutureGraph" changes more difficult. Callers that are genuinely interested in this behavior can wrap the Future in a FutureIterator and use "setUpdateInterval()" to get the same behavior. Test Plan: Grepped for "resolve()" and "resolvex()", updated callers. Maniphest Tasks: T11968 Differential Revision: https://secure.phabricator.com/D21031
This commit is contained in:
parent
33b9728b5f
commit
3df48c9257
5 changed files with 28 additions and 36 deletions
|
@ -25,13 +25,19 @@ abstract class Future extends Phobject {
|
||||||
* 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();
|
||||||
$wait = $this->getDefaultWait();
|
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();
|
||||||
do {
|
do {
|
||||||
$this->checkException();
|
$this->checkException();
|
||||||
if ($this->isReady()) {
|
if ($this->isReady()) {
|
||||||
|
@ -41,17 +47,6 @@ abstract class Future extends Phobject {
|
||||||
$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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ abstract class FutureProxy extends Future {
|
||||||
return $this->getProxiedFuture()->isReady();
|
return $this->getProxiedFuture()->isReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resolve($timeout = null) {
|
public function resolve() {
|
||||||
$this->getProxiedFuture()->resolve($timeout);
|
$this->getProxiedFuture()->resolve();
|
||||||
return $this->getResult();
|
return $this->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -231,15 +231,7 @@ final class ExecFuture extends PhutilExecutableFuture {
|
||||||
/**
|
/**
|
||||||
* Permanently discard the stdout and stderr buffers and reset the read
|
* Permanently discard the stdout and stderr buffers and reset the read
|
||||||
* cursors. This is basically useful only if you are streaming a large amount
|
* cursors. This is basically useful only if you are streaming a large amount
|
||||||
* of data from some process:
|
* of data from some process.
|
||||||
*
|
|
||||||
* $future = new ExecFuture('zcat huge_file.gz');
|
|
||||||
* do {
|
|
||||||
* $done = $future->resolve(0.1); // Every 100ms,
|
|
||||||
* list($stdout) = $future->read(); // read output...
|
|
||||||
* echo $stdout; // send it somewhere...
|
|
||||||
* $future->discardBuffers(); // and then free the buffers.
|
|
||||||
* } while ($done === null);
|
|
||||||
*
|
*
|
||||||
* Conceivably you might also need to do this if you're writing a client using
|
* Conceivably you might also need to do this if you're writing a client using
|
||||||
* @{class:ExecFuture} and `netcat`, but you probably should not do that.
|
* @{class:ExecFuture} and `netcat`, but you probably should not do that.
|
||||||
|
@ -316,8 +308,8 @@ final class ExecFuture extends PhutilExecutableFuture {
|
||||||
* @return pair <$stdout, $stderr> pair.
|
* @return pair <$stdout, $stderr> pair.
|
||||||
* @task resolve
|
* @task resolve
|
||||||
*/
|
*/
|
||||||
public function resolvex($timeout = null) {
|
public function resolvex() {
|
||||||
list($err, $stdout, $stderr) = $this->resolve($timeout);
|
list($err, $stdout, $stderr) = $this->resolve();
|
||||||
if ($err) {
|
if ($err) {
|
||||||
$cmd = $this->getCommand();
|
$cmd = $this->getCommand();
|
||||||
|
|
||||||
|
@ -352,8 +344,8 @@ final class ExecFuture extends PhutilExecutableFuture {
|
||||||
* @return array PHP array, decoded from JSON command output.
|
* @return array PHP array, decoded from JSON command output.
|
||||||
* @task resolve
|
* @task resolve
|
||||||
*/
|
*/
|
||||||
public function resolveJSON($timeout = null) {
|
public function resolveJSON() {
|
||||||
list($stdout, $stderr) = $this->resolvex($timeout);
|
list($stdout, $stderr) = $this->resolvex();
|
||||||
if (strlen($stderr)) {
|
if (strlen($stderr)) {
|
||||||
$cmd = $this->getCommand();
|
$cmd = $this->getCommand();
|
||||||
throw new CommandException(
|
throw new CommandException(
|
||||||
|
|
|
@ -59,13 +59,18 @@ final class ExecFutureTestCase extends PhutilTestCase {
|
||||||
|
|
||||||
public function testResolveTimeoutTestShouldRunLessThan1Sec() {
|
public function testResolveTimeoutTestShouldRunLessThan1Sec() {
|
||||||
// NOTE: This tests interactions between the resolve() timeout and the
|
// NOTE: This tests interactions between the resolve() timeout and the
|
||||||
// ExecFuture timeout, which are similar but not identical.
|
// resolution timeout, which are somewhat similar but not identical.
|
||||||
|
|
||||||
$future = $this->newSleep(32000)->start();
|
$future = $this->newSleep(32000)->start();
|
||||||
$future->setTimeout(32000);
|
$future->setTimeout(32000);
|
||||||
|
|
||||||
// We expect this to return in 0.01s.
|
// We expect this to return in 0.01s.
|
||||||
$result = $future->resolve(0.01);
|
$iterator = (new FutureIterator(array($future)))
|
||||||
|
->setUpdateInterval(0.01);
|
||||||
|
foreach ($iterator as $resolved_result) {
|
||||||
|
$result = $resolved_result;
|
||||||
|
break;
|
||||||
|
}
|
||||||
$this->assertEqual($result, null);
|
$this->assertEqual($result, null);
|
||||||
|
|
||||||
// We expect this to now force the time out / kill immediately. If we don't
|
// We expect this to now force the time out / kill immediately. If we don't
|
||||||
|
|
|
@ -1717,9 +1717,9 @@ abstract class ArcanistWorkflow extends Phobject {
|
||||||
return $parser;
|
return $parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected function resolveCall(ConduitFuture $method, $timeout = null) {
|
final protected function resolveCall(ConduitFuture $method) {
|
||||||
try {
|
try {
|
||||||
return $method->resolve($timeout);
|
return $method->resolve();
|
||||||
} catch (ConduitClientException $ex) {
|
} catch (ConduitClientException $ex) {
|
||||||
if ($ex->getErrorCode() == 'ERR-CONDUIT-CALL') {
|
if ($ex->getErrorCode() == 'ERR-CONDUIT-CALL') {
|
||||||
echo phutil_console_wrap(
|
echo phutil_console_wrap(
|
||||||
|
|
Loading…
Reference in a new issue