Final fixes for web login

This commit is contained in:
Daniil Gentili 2019-06-13 14:58:31 +02:00
parent 2d70f51b2c
commit 35c20d9bff
3 changed files with 20 additions and 5 deletions

View File

@ -33,6 +33,7 @@ class API extends APIFactory
public $my_telegram_org_wrapper; public $my_telegram_org_wrapper;
public $asyncAPIPromise; public $asyncAPIPromise;
private $oldInstance = false; private $oldInstance = false;
private $destructing = false;
public function __magic_construct($params = [], $settings = []) public function __magic_construct($params = [], $settings = [])
{ {

View File

@ -152,7 +152,7 @@ class MTProto extends AsyncConstruct implements TLCallback
public $phoneConfigWatcherId; public $phoneConfigWatcherId;
public $feeders = []; public $feeders = [];
public $updaters = []; public $updaters = [];
private $destructing = false; // Avoid problems with exceptions thrown by forked strands, see tools
public function __magic_construct($settings = []) public function __magic_construct($settings = [])
{ {
$this->setInitPromise($this->__construct_async($settings)); $this->setInitPromise($this->__construct_async($settings));

View File

@ -281,8 +281,12 @@ trait Tools
if ($promise instanceof Promise) { if ($promise instanceof Promise) {
$promise->onResolve(function ($e, $res) use ($file) { $promise->onResolve(function ($e, $res) use ($file) {
if ($e) { if ($e) {
if (isset($this)) {
$this->rethrow($e, $file);
} else {
self::rethrow($e, $file); self::rethrow($e, $file);
} }
}
}); });
} }
@ -304,7 +308,7 @@ trait Tools
$logger->logger("Got the following exception within a forked strand$file, trying to rethrow"); $logger->logger("Got the following exception within a forked strand$file, trying to rethrow");
if ($e->getMessage() === "Cannot get return value of a generator that hasn't returned") { if ($e->getMessage() === "Cannot get return value of a generator that hasn't returned") {
$logger->logger("Well you know, this might actually not be the actual exception, scroll up in the logs to see the actual exception"); $logger->logger("Well you know, this might actually not be the actual exception, scroll up in the logs to see the actual exception");
if (!isset($zis->destructing)) Promise\rethrow(new Failure($e)); if (!$zis || !$zis->destructing) Promise\rethrow(new Failure($e));
} else { } else {
$logger->logger($e); $logger->logger($e);
Promise\rethrow(new Failure($e)); Promise\rethrow(new Failure($e));
@ -317,12 +321,22 @@ trait Tools
$deferred = new Deferred(); $deferred = new Deferred();
$a->onResolve(static function ($e, $res) use ($b, $deferred) { $a->onResolve(static function ($e, $res) use ($b, $deferred) {
if ($e) { if ($e) {
return self::rethrow($e); if (isset($this)) {
$this->rethrow($e, $file);
} else {
self::rethrow($e, $file);
}
return;
} }
$b = self::call($b()); $b = self::call($b());
$b->onResolve(static function ($e, $res) use ($deferred) { $b->onResolve(static function ($e, $res) use ($deferred) {
if ($e) { if ($e) {
return self::rethrow($e); if (isset($this)) {
$this->rethrow($e, $file);
} else {
self::rethrow($e, $file);
}
return;
} }
$deferred->resolve($res); $deferred->resolve($res);
}); });