mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-23 00:11:20 +01:00
Bring back callFork
This commit is contained in:
parent
70e645373c
commit
e0ba1cf5bb
@ -92,7 +92,6 @@ Want to add your own open-source project to this list? [Click here!](https://doc
|
||||
* [Broadcasting messages to all users](https://docs.madelineproto.xyz/docs/BROADCAST.html)
|
||||
* [Handling updates (new messages & other events)](https://docs.madelineproto.xyz/docs/UPDATES.html)
|
||||
* [Async Event driven](https://docs.madelineproto.xyz/docs/UPDATES.html#async-event-driven)
|
||||
* [Built-in database driver](https://docs.madelineproto.xyz/docs/UPDATES.html#built-in-database-driver)
|
||||
* [Self-restart on webhosts](https://docs.madelineproto.xyz/docs/UPDATES.html#self-restart-on-webhosts)
|
||||
* [Async Event driven multi-account](https://docs.madelineproto.xyz/docs/UPDATES.html#async-event-driven-multiaccount)
|
||||
* [Noop (default)](https://docs.madelineproto.xyz/docs/UPDATES.html#noop)
|
||||
@ -194,6 +193,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc
|
||||
* [Async forking](https://docs.madelineproto.xyz/docs/ASYNC.html#async-forking-does-async-green-thread-forking)
|
||||
* [Async flock](https://docs.madelineproto.xyz/docs/ASYNC.html#async-flock)
|
||||
* [MadelineProto async loop APIs](https://docs.madelineproto.xyz/docs/ASYNC.html#async-loop-apis)
|
||||
* [FAQ](https://docs.madelineproto.xyz/docs/FAQ.html)
|
||||
* [Using methods](https://docs.madelineproto.xyz/docs/USING_METHODS.html)
|
||||
* [Named arguments (PHP 8+)](https://docs.madelineproto.xyz/docs/USING_METHODS.html#named-arguments)
|
||||
* [Peers](https://docs.madelineproto.xyz/docs/USING_METHODS.html#peers)
|
||||
@ -340,14 +340,14 @@ Want to add your own open-source project to this list? [Click here!](https://doc
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/contacts.deleteContacts.html" name="contacts.deleteContacts">Deletes several contacts from the list: contacts.deleteContacts</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/contacts.unblock.html" name="contacts.unblock">Deletes the user from the blacklist: contacts.unblock</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.deactivateAllUsernames.html" name="channels.deactivateAllUsernames">Disable all purchased usernames of a supergroup or channel: channels.deactivateAllUsernames</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#discardcall-array-call-array-rating-bool-need_debug-array-reason-danog-madelineproto-voip" name="discardCall">Discard call: discardCall</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#discardcall-array-call-array-reason-array-rating-bool-need_debug-danog-madelineproto-voip" name="discardCall">Discard call: discardCall</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#discardsecretchat-int-chat-void" name="discardSecretChat">Discard secret chat: discardSecretChat</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/help.dismissSuggestion.html" name="help.dismissSuggestion">Dismiss a suggestion, see here for more info »: help.dismissSuggestion</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/chatlists.hideChatlistUpdates.html" name="chatlists.hideChatlistUpdates">Dismiss new pending peers recently added to a chat folder deep link »: chatlists.hideChatlistUpdates</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.hideChatJoinRequest.html" name="messages.hideChatJoinRequest">Dismiss or approve a chat join request related to a specific chat or channel: messages.hideChatJoinRequest</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.hideAllChatJoinRequests.html" name="messages.hideAllChatJoinRequests">Dismiss or approve all join requests related to a specific chat or channel: messages.hideAllChatJoinRequests</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#downloadtoresponse-array-string-filecallbackinterface-messagemedia-amp-http-server-request-request-callable-cb-null-int-size-null-string-name-null-string-mime-amp-http-server-response" name="downloadToResponse">Download file to amphp/http-server response: downloadToResponse</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#downloadtobrowser-array-string-filecallbackinterface-messagemedia-null-callable-cb-null-int-size-null-string-mime-null-string-name-void" name="downloadToBrowser">Download file to browser: downloadToBrowser</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#downloadtoresponse-array-string-filecallbackinterface-messagemedia-amp-http-server-request-request-callable-cb-null-int-size-null-string-mime-null-string-name-amp-http-server-response" name="downloadToResponse">Download file to amphp/http-server response: downloadToResponse</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#downloadtobrowser-array-string-filecallbackinterface-messagemedia-null-callable-cb-null-int-size-null-string-name-null-string-mime-void" name="downloadToBrowser">Download file to browser: downloadToBrowser</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#downloadtocallable-mixed-messagemedia-callable-filecallbackinterface-callable-callable-cb-bool-seekable-int-offset-int-end-int-part_size-mixed" name="downloadToCallable">Download file to callable: downloadToCallable</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#downloadtodir-mixed-messagemedia-string-filecallbackinterface-dir-callable-cb-mixed" name="downloadToDir">Download file to directory: downloadToDir</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#downloadtostream-mixed-messagemedia-mixed-filecallbackinterface-resource-amp-bytestream-writablestream-stream-callable-cb-int-offset-int-end-mixed" name="downloadToStream">Download file to stream: downloadToStream</a>
|
||||
@ -385,6 +385,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/account.getSavedRingtones.html" name="account.getSavedRingtones">Fetch saved notification sounds: account.getSavedRingtones</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getMessageEditData.html" name="messages.getMessageEditData">Find out if a media message's caption can be edited: messages.getMessageEditData</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/account.finishTakeoutSession.html" name="account.finishTakeoutSession">Finish account takeout session: account.finishTakeoutSession</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#callfork-generator-amp-future-callable-promise-mixed-args-amp-future-t-" name="callFork">Fork a new green thread and execute the passed function in the background: callFork</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#broadcastforwardmessages-mixed-from_peer-list-int-message_ids-bool-drop_author-danog-madelineproto-broadcast-filter-filter-int" name="broadcastForwardMessages">Forwards a list of messages to all peers (users, chats, channels) of the bot: broadcastForwardMessages</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.forwardMessages.html" name="messages.forwardMessages">Forwards messages by their IDs: messages.forwardMessages</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#genvectorhash-array-ints-string" name="genVectorHash">Generate MTProto vector hash: genVectorHash</a>
|
||||
|
@ -203,23 +203,26 @@ abstract class AsyncTools extends StrTools
|
||||
} while (true);
|
||||
}
|
||||
/**
|
||||
* Call promise in background.
|
||||
* Fork a new green thread and execute the passed function in the background.
|
||||
*
|
||||
* @template T
|
||||
*
|
||||
* @param \Closure(...):T $closure Function to execute
|
||||
* @param mixed ...$args Arguments forwarded to the function when forking the thread.
|
||||
*
|
||||
* @return Future<T>
|
||||
*
|
||||
* @deprecated Coroutines are deprecated since amp v3
|
||||
* @param Generator|Future $promise Promise to resolve
|
||||
* @param ?\Generator|Future $actual Promise to resolve instead of $promise
|
||||
* @param string $file File
|
||||
* @psalm-suppress InvalidScope
|
||||
*/
|
||||
public static function callFork(Generator|Future $promise, $actual = null, string $file = ''): mixed
|
||||
public static function callFork(callable|Generator|Future $callable, ...$args): Future
|
||||
{
|
||||
if ($actual) {
|
||||
$promise = $actual;
|
||||
if (\is_callable($callable)) {
|
||||
$callable = async($callable, ...$args);
|
||||
}
|
||||
if ($promise instanceof Generator) {
|
||||
$promise = self::call($promise);
|
||||
if ($callable instanceof Generator) {
|
||||
$callable = self::call($callable);
|
||||
}
|
||||
return $promise;
|
||||
return $callable;
|
||||
}
|
||||
/**
|
||||
* Call promise in background, deferring execution.
|
||||
|
@ -291,17 +291,20 @@ abstract class InternalDoc
|
||||
return \danog\MadelineProto\AsyncTools::call($promise);
|
||||
}
|
||||
/**
|
||||
* Call promise in background.
|
||||
* Fork a new green thread and execute the passed function in the background.
|
||||
*
|
||||
* @template T
|
||||
*
|
||||
* @param \Closure(...):T $closure Function to execute
|
||||
* @param mixed ...$args Arguments forwarded to the function when forking the thread.
|
||||
*
|
||||
* @return Future<T>
|
||||
*
|
||||
* @deprecated Coroutines are deprecated since amp v3
|
||||
* @param Generator|Future $promise Promise to resolve
|
||||
* @param ?\Generator|Future $actual Promise to resolve instead of $promise
|
||||
* @param string $file File
|
||||
* @psalm-suppress InvalidScope
|
||||
*/
|
||||
public static function callFork(\Generator|\Amp\Future $promise, $actual = null, string $file = ''): mixed
|
||||
public static function callFork(\Generator|\Amp\Future|callable $promise, ...$args): \Amp\Future
|
||||
{
|
||||
return \danog\MadelineProto\AsyncTools::callFork($promise, $actual, $file);
|
||||
return \danog\MadelineProto\AsyncTools::callFork($promise, ...$args);
|
||||
}
|
||||
/**
|
||||
* Call promise in background, deferring execution.
|
||||
|
@ -394,7 +394,10 @@ trait ResponseHandler
|
||||
EventLoop::delay((float) $seconds, fn () => $this->methodRecall(['message_id' => $msgId]));
|
||||
return null;
|
||||
}
|
||||
if (\str_starts_with($response['error_message'], 'FLOOD_WAIT_')) {
|
||||
return fn () => new FloodWaitError($response['error_message'], $response['error_code'], $request->getConstructor());
|
||||
}
|
||||
// no break
|
||||
default:
|
||||
return fn () => new RPCErrorException($response['error_message'], $response['error_code'], $request->getConstructor());
|
||||
}
|
||||
|
@ -99,6 +99,7 @@ $order = [
|
||||
'SECRET_CHATS',
|
||||
'PROXY',
|
||||
'ASYNC',
|
||||
'FAQ',
|
||||
'USING_METHODS',
|
||||
'CONTRIB',
|
||||
'TEMPLATES',
|
||||
|
Loading…
x
Reference in New Issue
Block a user