1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 08:12:40 +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:
epriestley 2020-02-26 08:35:29 -08:00
parent 33b9728b5f
commit 3df48c9257
5 changed files with 28 additions and 36 deletions

View file

@ -25,12 +25,18 @@ abstract class Future extends Phobject {
* Resolve a future and return its result, blocking until the result is ready
* if necessary.
*
* @param float Optional timeout after which resolution will pause and
* execution will return to the caller.
* @return mixed Future result, or null if the timeout is hit.
* @return wild Future result.
*/
public function resolve($timeout = null) {
$start = microtime(true);
public function resolve() {
$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();
do {
$this->checkException();
@ -41,17 +47,6 @@ abstract class Future extends Phobject {
$read = $this->getReadSockets();
$write = $this->getWriteSockets();
if ($timeout !== null) {
$elapsed = microtime(true) - $start;
if ($elapsed > $timeout) {
$this->checkException();
return null;
} else {
$wait = $timeout - $elapsed;
}
}
if ($read || $write) {
self::waitForSockets($read, $write, $wait);
}

View file

@ -30,8 +30,8 @@ abstract class FutureProxy extends Future {
return $this->getProxiedFuture()->isReady();
}
public function resolve($timeout = null) {
$this->getProxiedFuture()->resolve($timeout);
public function resolve() {
$this->getProxiedFuture()->resolve();
return $this->getResult();
}

View file

@ -231,15 +231,7 @@ final class ExecFuture extends PhutilExecutableFuture {
/**
* Permanently discard the stdout and stderr buffers and reset the read
* cursors. This is basically useful only if you are streaming a large amount
* 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);
* of data from some process.
*
* 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.
@ -316,8 +308,8 @@ final class ExecFuture extends PhutilExecutableFuture {
* @return pair <$stdout, $stderr> pair.
* @task resolve
*/
public function resolvex($timeout = null) {
list($err, $stdout, $stderr) = $this->resolve($timeout);
public function resolvex() {
list($err, $stdout, $stderr) = $this->resolve();
if ($err) {
$cmd = $this->getCommand();
@ -352,8 +344,8 @@ final class ExecFuture extends PhutilExecutableFuture {
* @return array PHP array, decoded from JSON command output.
* @task resolve
*/
public function resolveJSON($timeout = null) {
list($stdout, $stderr) = $this->resolvex($timeout);
public function resolveJSON() {
list($stdout, $stderr) = $this->resolvex();
if (strlen($stderr)) {
$cmd = $this->getCommand();
throw new CommandException(

View file

@ -59,13 +59,18 @@ final class ExecFutureTestCase extends PhutilTestCase {
public function testResolveTimeoutTestShouldRunLessThan1Sec() {
// 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->setTimeout(32000);
// 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);
// We expect this to now force the time out / kill immediately. If we don't

View file

@ -1717,9 +1717,9 @@ abstract class ArcanistWorkflow extends Phobject {
return $parser;
}
final protected function resolveCall(ConduitFuture $method, $timeout = null) {
final protected function resolveCall(ConduitFuture $method) {
try {
return $method->resolve($timeout);
return $method->resolve();
} catch (ConduitClientException $ex) {
if ($ex->getErrorCode() == 'ERR-CONDUIT-CALL') {
echo phutil_console_wrap(