mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Optimize registering of callbacks
This commit is contained in:
parent
96042d13ec
commit
0479c24e5a
1 changed files with 12 additions and 15 deletions
|
|
@ -14,21 +14,10 @@ APP_EXECUTOR_KEY = 'APP_EXECUTOR'
|
||||||
|
|
||||||
|
|
||||||
def _setup_callbacks(executor, on_startup, on_shutdown):
|
def _setup_callbacks(executor, on_startup, on_shutdown):
|
||||||
if on_startup is None:
|
if on_startup is not None:
|
||||||
pass
|
|
||||||
elif callable(on_startup):
|
|
||||||
executor.on_startup(on_startup)
|
executor.on_startup(on_startup)
|
||||||
else:
|
if on_shutdown is not None:
|
||||||
for callback in on_startup:
|
|
||||||
executor.on_startup(callback)
|
|
||||||
|
|
||||||
if on_shutdown is None:
|
|
||||||
pass
|
|
||||||
elif callable(on_shutdown):
|
|
||||||
executor.on_shutdown(on_shutdown)
|
executor.on_shutdown(on_shutdown)
|
||||||
else:
|
|
||||||
for callback in on_shutdown:
|
|
||||||
executor.on_shutdown(callback)
|
|
||||||
|
|
||||||
|
|
||||||
def start_polling(dispatcher, *, loop=None, skip_updates=False, reset_webhook=True,
|
def start_polling(dispatcher, *, loop=None, skip_updates=False, reset_webhook=True,
|
||||||
|
|
@ -83,11 +72,15 @@ class Executor:
|
||||||
|
|
||||||
def on_startup(self, callback: callable, polling=True, webhook=True):
|
def on_startup(self, callback: callable, polling=True, webhook=True):
|
||||||
self._check_frozen()
|
self._check_frozen()
|
||||||
|
|
||||||
if not webhook and not polling:
|
if not webhook and not polling:
|
||||||
warn('This action has no effect!', UserWarning)
|
warn('This action has no effect!', UserWarning)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if isinstance(callback, (list, tuple, set)):
|
||||||
|
for cb in callback:
|
||||||
|
self.on_startup(cb, polling, webhook)
|
||||||
|
return
|
||||||
|
|
||||||
if polling:
|
if polling:
|
||||||
self._on_startup_polling.append(callback)
|
self._on_startup_polling.append(callback)
|
||||||
if webhook:
|
if webhook:
|
||||||
|
|
@ -95,11 +88,15 @@ class Executor:
|
||||||
|
|
||||||
def on_shutdown(self, callback: callable, polling=True, webhook=True):
|
def on_shutdown(self, callback: callable, polling=True, webhook=True):
|
||||||
self._check_frozen()
|
self._check_frozen()
|
||||||
|
|
||||||
if not webhook and not polling:
|
if not webhook and not polling:
|
||||||
warn('This action has no effect!', UserWarning)
|
warn('This action has no effect!', UserWarning)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if isinstance(callback, (list, tuple, set)):
|
||||||
|
for cb in callback:
|
||||||
|
self.on_shutdown(cb, polling, webhook)
|
||||||
|
return
|
||||||
|
|
||||||
if polling:
|
if polling:
|
||||||
self._on_shutdown_polling.append(callback)
|
self._on_shutdown_polling.append(callback)
|
||||||
if webhook:
|
if webhook:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue