1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 07:14:39 +01:00
This commit is contained in:
Daniil Gentili 2021-04-22 22:55:24 +02:00
parent 0514b5fcf5
commit 4c1fb332f5
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
4 changed files with 11 additions and 14 deletions

View File

@ -178,7 +178,7 @@ class API extends InternalDoc
$this->session = new SessionPaths($session);
$this->wrapper = new APIWrapper($this, $this->exportNamespace());
$this->setInitPromise((function () use ($settings) { yield new \Amp\Success; return yield from $this->internalInitAPI($settings); })());
$this->setInitPromise($this->internalInitAPI($settings));
foreach (\get_class_vars(APIFactory::class) as $key => $var) {
if (\in_array($key, ['namespace', 'API', 'lua', 'async', 'asyncAPIPromise', 'methods'])) {
continue;

View File

@ -34,7 +34,7 @@ class AsyncConstruct
/**
* Async init promise.
*
* @var Promise|null|boolean
* @var Promise|\Generator|null|boolean
*/
private $asyncInitPromise;
/**
@ -46,6 +46,7 @@ class AsyncConstruct
{
if ($this->asyncInitPromise) {
Tools::wait($this->asyncInitPromise);
$this->asyncInitPromise = null;
}
}
/**
@ -57,6 +58,7 @@ class AsyncConstruct
{
if ($this->asyncInitPromise) {
yield $this->asyncInitPromise;
$this->asyncInitPromise = null;
}
}
/**
@ -90,13 +92,6 @@ class AsyncConstruct
*/
public function setInitPromise($promise): void
{
$this->asyncInitPromise = Tools::call($promise);
$this->asyncInitPromise->onResolve(
function (?\Throwable $error, $result): void {
if (!$error) {
$this->asyncInitPromise = null;
}
}
);
$this->asyncInitPromise = $promise;
}
}

View File

@ -192,7 +192,9 @@ class Server extends SignalLoop
if ($payload === self::SHUTDOWN) {
$this->signal(null);
if (self::$shutdownDeferred) {
self::$shutdownDeferred->resolve();
$deferred = self::$shutdownDeferred;
self::$shutdownDeferred = null;
$deferred->resolve();
}
}
}

View File

@ -782,7 +782,7 @@ trait Files
{
if (\is_object($dir) && $dir instanceof FileCallbackInterface) {
$cb = $dir;
$dir = $dir->getFile();
$dir = yield $dir->getFile();
}
$messageMedia = (yield from $this->getDownloadInfo($messageMedia));
return yield from $this->downloadToFile($messageMedia, $dir.'/'.$messageMedia['name'].$messageMedia['ext'], $cb);
@ -802,7 +802,7 @@ trait Files
{
if (\is_object($file) && $file instanceof FileCallbackInterface) {
$cb = $file;
$file = $file->getFile();
$file = yield $file->getFile();
}
$file = Tools::absolute(\preg_replace('|/+|', '/', $file));
if (!yield exists($file)) {
@ -848,7 +848,7 @@ trait Files
$messageMedia = (yield from $this->getDownloadInfo($messageMedia));
if (\is_object($callable) && $callable instanceof FileCallbackInterface) {
$cb = $callable;
$callable = $callable->getFile();
$callable = yield $callable->getFile();
}
if (!\is_callable($callable)) {
throw new Exception('Wrong callable provided');