/** * Synchronously waits on a promise to resolve and returns an inspection state * array. * * Returns a state associative array containing a "state" key mapping to a * valid promise state. If the state of the promise is "fulfilled", the array * will contain a "value" key mapping to the fulfilled value of the promise. If * the promise is rejected, the array will contain a "reason" key mapping to * the rejection reason of the promise. * * @param PromiseInterface $promise Promise or value. * * @return array */ function inspect(PromiseInterface $promise) { try { return ['state' => PromiseInterface::FULFILLED, 'value' => $promise->wait()]; } catch (RejectionException $e) { return ['state' => 'rejected', 'reason' => $e->getReason()]; } catch (\Exception $e) { return ['state' => 'rejected', 'reason' => $e]; } }