From d7d4889c50c2998f37d214b15be41f70f9df5874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannes=20H=C3=B6ke?= Date: Thu, 5 Nov 2015 16:01:25 +0100 Subject: [PATCH] use run_async decorator in example --- examples/eventhandler_bot.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/eventhandler_bot.py b/examples/eventhandler_bot.py index 1d0d6c2b7..8eae61b57 100644 --- a/examples/eventhandler_bot.py +++ b/examples/eventhandler_bot.py @@ -11,7 +11,9 @@ inserted into the update queue for the bot to handle. """ import sys -from telegram.boteventhandler import BotEventHandler +from telegram import BotEventHandler +from telegram.boteventhandler import run_async +from time import sleep import re global last_chat_id @@ -35,9 +37,18 @@ def anyMessageHandler(bot, update): def unknownCommandHandler(bot, update): bot.sendMessage(update.message.chat_id, text='Command not recognized!') +@run_async def messageHandler(bot, update): + """ + Example for an asynchronous handler. It's not guaranteed that replies will + be in order when using @run_async + """ + + # Save last chat_id to use in reply handler global last_chat_id last_chat_id = update.message.chat_id + + sleep(2) # IO-heavy operation here bot.sendMessage(update.message.chat_id, text=update.message.text) def errorHandler(bot, error):