Use custom wait

This commit is contained in:
Daniil Gentili 2019-05-13 13:53:31 +02:00
parent be9c822d11
commit fd14f8c6b6

View File

@ -200,16 +200,28 @@ trait Tools
} elseif (!($promise instanceof Promise)) { } elseif (!($promise instanceof Promise)) {
return $promise; return $promise;
} }
$resolved = false;
do { do {
try { try {
return wait($promise); Loop::run(function () use (&$resolved, &$value, &$exception, $promise) {
} catch (\Throwable $e) { $promise->onResolve(function ($e, $v) use (&$resolved, &$value, &$exception) {
if ($e->getMessage() !== 'Loop stopped without resolving the promise') { Loop::stop();
//$this->logger->logger("AN EXCEPTION SURFACED " . $e, \danog\MadelineProto\Logger::ERROR); $resolved = true;
throw $e; $exception = $e;
} $value = $v;
});
});
} catch (\Throwable $throwable) {
throw new \Error("Loop exceptionally stopped without resolving the promise", 0, $throwable);
} }
} while (true); } while (!$resolved);
if ($exception) {
throw $exception;
}
return $value;
} }
public function all($promises) public function all($promises)
{ {