def wait_once(self, cb=None, **params): if cb is not None: check_callable(cb) params.update({"feed": "longpoll"}) resp = self.db.res.get("_changes", **params) with resp.body_stream() as body: sock = self.patch_socket(body.reader.unreader.sock) body.reader.unreader.sock = sock try: while True: if self.wait_read(sock): buf = [] while True: chunk = body.read() if not chunk: break buf.append(chunk) if cb is not None: self.spawn(self.handle, cb, "".join(buf)) self.sleep(0.1) else: ret = "".join(buf) try: return json.loads(ret) except ValueError: return ret break except NoMoreData: pass except (SystemExit, KeyboardInterrupt): pass
def wait_once(self, cb=None, **params): if cb is None: return super(EventletConsumer, self).wait_once(**params) check_callable(cb) params.update({"feed": "longpoll"}) consumer = LongPollChangeConsumer(self.db, callback=cb, **params) consumer.wait()
def wait_once(self, cb=None, **params): if cb is None: return super(GeventConsumer, self).wait_once(**params) check_callable(cb) params.update({"feed": "longpoll"}) LongPollChangeConsumer.spawn(self.db, callback=cb, **params).join()
def fetch(self, cb, **params): resp = self.db.res.get("_changes", **params) if cb is not None: check_callable(cb) self.spawn(cb, resp.json_body) self.sleep(0.1) else: return resp.json_body
def wait(self, cb, **params): check_callable(cb) params.update({"feed": "continuous"}) resp = self.db.res.get("_changes", **params) if resp.headers.get('transfer-encoding') == "chunked": chunked = True else: chunked = False change_handler = continuous_changes_handler(resp, cb, chunked) asyncore.loop()
def wait_once(self, cb=None, **params): if cb is not None: check_callable(cb) params.update({"feed": "longpoll"}) resp = self.db.res.get("_changes", **params) buf = "" with resp.body_stream() as body: while True: data = body.read() if not data: break buf += data ret = json.loads(buf) if cb is not None: cb(ret) return return ret
def wait_async(self, cb, **params): check_callable(cb) params.update({"feed": "continuous"}) consumer = ContinuousChangeConsumer(self.db, callback=cb, **params) return consumer.wait_async()
def wait_once_async(self, cb, **params): check_callable(cb) params.update({"feed": "longpoll"}) consumer = LongPollChangeConsumer(self.db, callback=cb, **params) return consumer.wait_async()
def wait(self, cb, **params): check_callable(cb) params.update({"feed": "continuous"}) ContinuousChangeConsumer.spawn(self.db, callback=cb, **params).join()