1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 04:08:59 +01:00
This commit is contained in:
Daniil Gentili 2024-06-27 18:26:14 +02:00
parent 935e0daf86
commit b63099b130
4 changed files with 30 additions and 8 deletions

View File

@ -2340,6 +2340,7 @@
<code><![CDATA[$media['media']]]></code>
</MixedArrayAccess>
<MixedAssignment>
<code><![CDATA[$arg]]></code>
<code><![CDATA[$callable]]></code>
<code><![CDATA[$callable]]></code>
<code><![CDATA[$dir]]></code>
@ -2510,6 +2511,9 @@
<code><![CDATA[Wrapper]]></code>
<code><![CDATA[Wrapper]]></code>
</PropertyNotSetInConstructor>
<PropertyTypeCoercion>
<code><![CDATA[$this->callbackIds]]></code>
</PropertyTypeCoercion>
<UnsafeInstantiation>
<code><![CDATA[new $class($this, $ids)]]></code>
</UnsafeInstantiation>
@ -2518,10 +2522,13 @@
<code><![CDATA[$this->callbackIds[] = &$callback]]></code>
</UnsupportedReferenceUsage>
</file>
<file src="src/Ipc/Wrapper/Cancellation.php">
<file src="src/Ipc/Wrapper/CancellationInner.php">
<MixedAssignment>
<code><![CDATA[$id]]></code>
</MixedAssignment>
<MixedReturnStatement>
<code><![CDATA[$id]]></code>
<code><![CDATA[$this->__call('isRequested')]]></code>
<code><![CDATA[$this->__call('unsubscribe', [$callback])]]></code>
</MixedReturnStatement>
</file>
<file src="src/Ipc/Wrapper/ReadableStream.php">
@ -2536,6 +2543,14 @@
<code><![CDATA[$this->__call('isReadable')]]></code>
</MixedReturnStatement>
</file>
<file src="src/Ipc/Wrapper/WrappedCancellation.php">
<DocblockTypeContradiction>
<code><![CDATA[$this->handlers[$id]]]></code>
</DocblockTypeContradiction>
<RedundantConditionGivenDocblockType>
<code><![CDATA[$this->handlers[$id]?->complete()]]></code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Ipc/Wrapper/WritableStream.php">
<MixedReturnStatement>
<code><![CDATA[$this->__call('isWritable')]]></code>

View File

@ -121,8 +121,7 @@ final class Wrapper extends ClientAbstract
}
$ids = [];
foreach (get_class_methods($callback) as $method) {
//$id = $this->id++;
$id = $this->id++.'_'.$method;
$id = $this->id++;
$this->callbacks[$id] = [$callback, $method];
$ids[$method] = $id;
}

View File

@ -25,6 +25,9 @@ use danog\MadelineProto\Ipc\ClientAbstract;
*/
final class Cancellation implements AmpCancellation
{
/**
* @var array<string, true> $handlers
*/
private array $handlers = [];
private CancellationInner $inner;
/**
@ -50,7 +53,9 @@ final class Cancellation implements AmpCancellation
*/
public function subscribe(\Closure $callback): string
{
return $this->inner->subscribe($callback);
$id = $this->inner->subscribe($callback);
$this->handlers[$id] = true;
return $id;
}
/**
@ -60,6 +65,7 @@ final class Cancellation implements AmpCancellation
*/
public function unsubscribe(string $id): void
{
unset($this->handlers[$id]);
$this->inner->unsubscribe($id);
}
@ -83,7 +89,7 @@ final class Cancellation implements AmpCancellation
public function __destruct()
{
foreach ($this->handlers as $handler) {
foreach ($this->handlers as $handler => $_) {
$this->inner->unsubscribe($handler);
}
}

View File

@ -56,8 +56,10 @@ final class WrappedCancellation
*/
public function unsubscribe(string $id): void
{
$this->handlers[$id]?->complete();
unset($this->handlers[$id]);
if (isset($this->handlers[$id])) {
$this->handlers[$id]->complete();
unset($this->handlers[$id]);
}
}
/**