mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 22:11:32 +00:00
Fix message timing on empty queue
This commit is contained in:
parent
e58f0b1d04
commit
e5d0e91e93
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user