class MlanSearch(object): def __init__(self): self.tasklet = None def search(self, line): if self.tasklet is None: self.reqchannel = Channel() self.queued = {} self.tasklet = Tasklet(self._checker) self.tasklet() ch = Channel() if line in self.queued: self.queued[line].append(ch) else: self.queued[line] = [ch] self.reqchannel.send(line) return ch.recv() def _checker(self): while True: line = self.reqchannel.recv() waiters = self.reqchannel[line] del self.reqchannel[line] for waiter in waiters: if waiter.has_receiver(): waiter.send(["abc", "def", "ghi"])
def search(self, line): if self.tasklet is None: self.reqchannel = Channel() self.queued = {} self.tasklet = Tasklet(self._checker) self.tasklet() ch = Channel() if line in self.queued: self.queued[line].append(ch) else: self.queued[line] = [ch] self.reqchannel.send(line) return ch.recv()