resolve(); * } catch (AphrontQueryException $ex) { * } * } * * `$result` contains a list of dicts for select queries or number of modified * rows for modification queries. */ final class QueryFuture extends Future { private static $futures = array(); private $conn; private $query; private $id; private $async; private $profilerCallID; public function __construct( AphrontDatabaseConnection $conn, $pattern/* , ... */) { $this->conn = $conn; $args = func_get_args(); $args = array_slice($args, 2); $this->query = vqsprintf($conn, $pattern, $args); self::$futures[] = $this; $this->id = last_key(self::$futures); } public function isReady() { if ($this->canResolve()) { return true; } if (!$this->async) { $profiler = PhutilServiceProfiler::getInstance(); $this->profilerCallID = $profiler->beginServiceCall( array( 'type' => 'query', 'query' => $this->query, 'async' => true, )); $this->async = $this->conn->asyncQuery($this->query); return false; } $conns = array(); $asyncs = array(); foreach (self::$futures as $id => $future) { if ($future->async) { $conns[$id] = $future->conn; $asyncs[$id] = $future->async; } } $this->processResults($this->conn->resolveAsyncQueries($conns, $asyncs)); if ($this->canResolve()) { return true; } return false; } private function processResults(array $results) { foreach ($results as $id => $result) { $future = self::$futures[$id]; if ($result instanceof Exception) { $future->exception = $result; } else { $future->result = $result; } unset(self::$futures[$id]); if ($future->profilerCallID) { $profiler = PhutilServiceProfiler::getInstance(); $profiler->endServiceCall($future->profilerCallID, array()); } } } }