MsgResults = {} # Global hash of outstanding messages.
MsgID = 0 # Next msgid to use
def NextID():
global MsgID
MsgID = MsgID + 2
return MsgID
def AsyncMsgHandler(reply):
MsgResults[reply["msgid"]].set(reply["value"])
class API(object):
def _AsyncMsgEmit(self, msg):
msgid = NextID()
MsgResults[msgid] = AsyncResult();
msg["msgid"] = msgid
self.emit("msg", msg, callback=AsyncMsgHandler)
print "Waiting"
MsgResults[msgid].wait()
print "Waited", MsgResults[msgid].value
value = MsgResults[msgid].value
del MsgResults[msgid]
return value;