public function testKnowsIfSettled() { $p = new RejectedPromise(null); $this->assertTrue(P\is_settled($p)); $p = new Promise(); $this->assertFalse(P\is_settled($p)); }
/** * Api mail send * @return [json] Api return */ private function apiMailSend($uri, $gateway, $params) { // change mail gateway $this->setGateways($gateway); // get Async config $async = $this->getAsync(); if (!$async) { // send $client = new \GuzzleHttp\Client(); // sync send $res = $client->request('post', $uri, ['form_params' => $params]); return (string) $res->getBody(); } else { // async send $curl = new CurlMultiHandler(); $handler = HandlerStack::create($curl); // send $client = new \GuzzleHttp\Client(['handler' => $handler]); $promise = $client->requestAsync('post', $uri, ['form_params' => $params]); if (isset($params['xsmtpapi'])) { $params['xsmtpapi'] = json_encode(json_decode($params['xsmtpapi']), JSON_UNESCAPED_UNICODE); } $promise->then(function (ResponseInterface $res) use($params) { $fileDir = $this->getSendCloudLogDir(); $this->logInfo('[' . Carbon::now($this->local)->format('Y-m-d H:i:s') . ']' . json_encode($params, JSON_UNESCAPED_UNICODE) . chr(10), $fileDir); }, function (RequestException $e) use($params) { $fileDir = $this->getSendCloudFailLogDir(); $this->logInfo('[' . Carbon::now($this->local)->format('Y-m-d H:i:s') . ']' . json_encode($params, JSON_UNESCAPED_UNICODE) . chr(10), $fileDir); }); $aggregate = Promise\all([$promise]); while (!Promise\is_settled($aggregate)) { $curl->tick(); } return true; } }