-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove if condition in _run_handlers #11
Comments
Hi,
It would be nice to have this! Maybe it's better to name this method like
def add_update_handler(self, func: Callable):
# later here we can add a second parameter: type
# to register handlers for specific types
if func not in self._update_handlers:
self._message_handlers.append(func)
def _run_handlers(self, update: Dict[Any, Any]) -> None:
if update.get('@type') == 'updateNewMessage':
for handler in self._message_handlers:
self._workers_queue.put(
(handler, update),
timeout=self._queue_put_timeout,
)
for handler in self._update_handlers:
self._workers_queue.put(
(handler, update),
timeout=self._queue_put_timeout,
) If you have time, you can create a PR, if not, I will assign this issue to myself. :) |
Ok. Thanks for suggestion. Will do it this weekend and let u know. |
I did this way. If ok, will send a PR
I declared it as a dictionary. Then
|
👍 Overall it looks nice, exactly what I meant in the comment I would try to avoid big try-except block in the |
Ok.. got the point. As add update will be called only once, it should be ok. Where as run handlers will handle all calls, keeping it light weight is what you mean, I think.
|
Yes, exactly :) Also, change |
Fixed in #19 |
Hi
The if condition in
_run_handlers
is creating issues, when I try to test tgvoip example. I modified it asor we can create another method for
add_message_handler
likeadd_call_handler
and append functions to new list like _call_handler. In else condition use it.If ok, I can create a PR.
The text was updated successfully, but these errors were encountered: