1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 06:18:58 +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
{
$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']) {
$aargs['datacenter'] = $args['id']['dc_id'];
return $this->API->methodCallAsyncWrite($method, $args, $aargs);
@ -185,7 +187,7 @@ trait CallHandler
queueId: $aargs['queue'] ?? null,
floodWaitLimit: $aargs['FloodWaitLimit'] ?? null,
resultDeferred: $response,
cancellation: $aargs['cancellation'] ?? null,
cancellation: $cancellation,
);
if (isset($aargs['msg_id'])) {
$message->setMsgId($aargs['msg_id']);

View File

@ -1086,6 +1086,7 @@ trait Files
$previous_promise = true;
$promises = [];
foreach ($params as $key => $param) {
$cancellation?->throwIfRequested();
$param['previous_promise'] = $previous_promise;
$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 {
@ -1147,6 +1148,7 @@ trait Files
}
//$x = 0;
while (true) {
$cancellation?->throwIfRequested();
try {
$res = $this->methodCallAsyncRead(
$cdn ? 'upload.getCdnFile' : 'upload.getFile',
@ -1167,6 +1169,7 @@ trait Files
}
}
}
$cancellation?->throwIfRequested();
if ($res['_'] === 'upload.fileCdnRedirect') {
$cdn = true;
@ -1204,8 +1207,9 @@ trait Files
$datacenter = 0;
}
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'];
if ($res['bytes'] === '') {
return 0;