diff --git a/tfw/components/frontend/message_queue_handler/message_queue_handler.py b/tfw/components/frontend/message_queue_handler/message_queue_handler.py index b661877..08613f0 100644 --- a/tfw/components/frontend/message_queue_handler/message_queue_handler.py +++ b/tfw/components/frontend/message_queue_handler/message_queue_handler.py @@ -27,14 +27,15 @@ class MessageQueueHandler: def _dispatch_messages(self): for message in iter(self._queue.get, None): - message['typing'] = not self._queue.empty() + is_queue_empty = self._queue.empty() + message['typing'] = not is_queue_empty self.connector.send_message(message) - self._sleep(self._get_sleep_time(message)) + self._sleep(self._get_sleep_time(message, is_queue_empty)) - def _get_sleep_time(self, message): + def _get_sleep_time(self, message, is_queue_empty): words_per_min = message['wpm'] if 'wpm' in message else self.wpm chars_per_min = self.avg_word_len * words_per_min / 60 - return len(message['message']) / chars_per_min + return 0 if is_queue_empty else len(message['message']) / chars_per_min def _sleep(self, seconds): poll_freq = self.drain_poll_freq