mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 01:54:53 +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):
|
||||
if on_startup is None:
|
||||
pass
|
||||
elif callable(on_startup):
|
||||
if on_startup is not None:
|
||||
executor.on_startup(on_startup)
|
||||
else:
|
||||
for callback in on_startup:
|
||||
executor.on_startup(callback)
|
||||
|
||||
if on_shutdown is None:
|
||||
pass
|
||||
elif callable(on_shutdown):
|
||||
if on_shutdown is not None:
|
||||
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,
|
||||
|
|
@ -83,11 +72,15 @@ class Executor:
|
|||
|
||||
def on_startup(self, callback: callable, polling=True, webhook=True):
|
||||
self._check_frozen()
|
||||
|
||||
if not webhook and not polling:
|
||||
warn('This action has no effect!', UserWarning)
|
||||
return
|
||||
|
||||
if isinstance(callback, (list, tuple, set)):
|
||||
for cb in callback:
|
||||
self.on_startup(cb, polling, webhook)
|
||||
return
|
||||
|
||||
if polling:
|
||||
self._on_startup_polling.append(callback)
|
||||
if webhook:
|
||||
|
|
@ -95,11 +88,15 @@ class Executor:
|
|||
|
||||
def on_shutdown(self, callback: callable, polling=True, webhook=True):
|
||||
self._check_frozen()
|
||||
|
||||
if not webhook and not polling:
|
||||
warn('This action has no effect!', UserWarning)
|
||||
return
|
||||
|
||||
if isinstance(callback, (list, tuple, set)):
|
||||
for cb in callback:
|
||||
self.on_shutdown(cb, polling, webhook)
|
||||
return
|
||||
|
||||
if polling:
|
||||
self._on_shutdown_polling.append(callback)
|
||||
if webhook:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue