1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 08:18:59 +01:00

Improve cancellation support

This commit is contained in:
Daniil Gentili 2023-10-01 21:46:16 +02:00
parent f06cce31ed
commit bb18b86310
4 changed files with 10 additions and 4 deletions

2
docs

@ -1 +1 @@
Subproject commit b3251b13da49ce7c88cd263d1b4859b50b428546 Subproject commit e5574eae36016400e3e56aad4a71b03e59458a2f

@ -1 +1 @@
Subproject commit 32214a5ad3aa7ffdf4cd7a1592b98990ca5a559b Subproject commit 453cf521d71f99f21f84fff96651c744b0f99a34

View File

@ -115,6 +115,8 @@ trait CallHandler
*/ */
public function methodCallAsyncWrite(string $method, array|callable $args = [], array $aargs = ['msg_id' => null]): WrappedFuture public function methodCallAsyncWrite(string $method, array|callable $args = [], array $aargs = ['msg_id' => null]): WrappedFuture
{ {
$cancellation = $aargs['cancellation'] ?? null;
$cancellation?->throwIfRequested();
if (\is_array($args) && isset($args['id']['_']) && isset($args['id']['dc_id']) && ($args['id']['_'] === 'inputBotInlineMessageID' || $args['id']['_'] === 'inputBotInlineMessageID64') && $this->datacenter != $args['id']['dc_id']) { if (\is_array($args) && isset($args['id']['_']) && isset($args['id']['dc_id']) && ($args['id']['_'] === 'inputBotInlineMessageID' || $args['id']['_'] === 'inputBotInlineMessageID64') && $this->datacenter != $args['id']['dc_id']) {
$aargs['datacenter'] = $args['id']['dc_id']; $aargs['datacenter'] = $args['id']['dc_id'];
return $this->API->methodCallAsyncWrite($method, $args, $aargs); return $this->API->methodCallAsyncWrite($method, $args, $aargs);
@ -185,7 +187,7 @@ trait CallHandler
queueId: $aargs['queue'] ?? null, queueId: $aargs['queue'] ?? null,
floodWaitLimit: $aargs['FloodWaitLimit'] ?? null, floodWaitLimit: $aargs['FloodWaitLimit'] ?? null,
resultDeferred: $response, resultDeferred: $response,
cancellation: $aargs['cancellation'] ?? null, cancellation: $cancellation,
); );
if (isset($aargs['msg_id'])) { if (isset($aargs['msg_id'])) {
$message->setMsgId($aargs['msg_id']); $message->setMsgId($aargs['msg_id']);

View File

@ -1086,6 +1086,7 @@ trait Files
$previous_promise = true; $previous_promise = true;
$promises = []; $promises = [];
foreach ($params as $key => $param) { foreach ($params as $key => $param) {
$cancellation?->throwIfRequested();
$param['previous_promise'] = $previous_promise; $param['previous_promise'] = $previous_promise;
$previous_promise = async($this->downloadPart(...), $messageMedia, $cdn, $datacenter, $old_dc, $ige, $cb, $param, $callable, $seekable, $cancellation); $previous_promise = async($this->downloadPart(...), $messageMedia, $cdn, $datacenter, $old_dc, $ige, $cb, $param, $callable, $seekable, $cancellation);
$previous_promise->map(static function (int $res) use (&$size): void { $previous_promise->map(static function (int $res) use (&$size): void {
@ -1147,6 +1148,7 @@ trait Files
} }
//$x = 0; //$x = 0;
while (true) { while (true) {
$cancellation?->throwIfRequested();
try { try {
$res = $this->methodCallAsyncRead( $res = $this->methodCallAsyncRead(
$cdn ? 'upload.getCdnFile' : 'upload.getFile', $cdn ? 'upload.getCdnFile' : 'upload.getFile',
@ -1167,6 +1169,7 @@ trait Files
} }
} }
} }
$cancellation?->throwIfRequested();
if ($res['_'] === 'upload.fileCdnRedirect') { if ($res['_'] === 'upload.fileCdnRedirect') {
$cdn = true; $cdn = true;
@ -1204,8 +1207,9 @@ trait Files
$datacenter = 0; $datacenter = 0;
} }
while ($cdn === false && $res['type']['_'] === 'storage.fileUnknown' && $res['bytes'] === '' && $this->datacenter->has(++$datacenter)) { while ($cdn === false && $res['type']['_'] === 'storage.fileUnknown' && $res['bytes'] === '' && $this->datacenter->has(++$datacenter)) {
$res = $this->methodCallAsyncRead('upload.getFile', $basic_param + $offset, ['heavy' => true, 'FloodWaitLimit' => 0, 'datacenter' => $datacenter]); $res = $this->methodCallAsyncRead('upload.getFile', $basic_param + $offset, ['heavy' => true, 'FloodWaitLimit' => 0, 'datacenter' => $datacenter, 'cancellation' => $cancellation]);
} }
$cancellation?->throwIfRequested();
$res['bytes'] = (string) $res['bytes']; $res['bytes'] = (string) $res['bytes'];
if ($res['bytes'] === '') { if ($res['bytes'] === '') {
return 0; return 0;