-
Notifications
You must be signed in to change notification settings - Fork 0
/
bus.py
42 lines (35 loc) · 1.18 KB
/
bus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from gevent.queue import Queue
class Bus(object):
def __init__(self):
self._out_queue = Queue()
self._in_queue = Queue()
def get_out_message(self):
"""Get message from out_queue (for server)"""
if self._out_queue.empty():
return None
else:
return self._out_queue.get_nowait()
def send_in_message(self, message):
"""Send message to plugins"""
if isinstance(message, list):
for m in message:
self._in_queue.put(m)
else:
self._in_queue.put(message)
def exist_out_messages(self):
return not self._out_queue.empty()
def get_in_message(self):
"""Get message from in_queue (for plugins)"""
if self._in_queue.empty():
return None
else:
return self._in_queue.get_nowait()
def send_out_message(self, message):
"""Method for plugins to send message to server"""
if isinstance(message, list):
for m in message:
self._out_queue.put(m)
else:
self._out_queue.put(message)
def exist_in_messages(self):
return not self._in_queue.empty()