# Path: stator/loop.py
# def parse_message(self, input):
#     raise RuntimeError("abstract method")
# 
# @_skip
# def blocking_io():
#     return False
# 
# class Socket(object):
# 
#     def __init__(self, id):
#         assert isinstance(id, INT_TYPES), (type(id), id)
#         self.id = id
#         TABLE.add(self)
# 
#     def close(self):
#         TABLE.remove(self.id)
# 
#     def parse_message(self, input):
#         raise RuntimeError("abstract method")
# 
#     def __repr__(self):
#         return '<{} {}>'.format(self.__class__.__name__,
#             repr(self.__dict__)[1:-1])
# 
# Path: stator/lib.py



import asyncio
import cbor
from collections import namedtuple
from functools import partial
from .loop import parse_message, blocking_io, Socket
from .lib import dll
from . import redis
        return f

    def parse_message(self, input):
        req_id = cbor.load(input)
        data = cbor.load(input)
        return _RedisResponse(req_id, data)


def dispatch_messages(loop, callback):
    while True:
        message = dll.stator_next_message(parse_message, blocking_io)
        if message is False:
            break
        elif message is None:
            continue
        elif isinstance(message, BaseException):
            raise message
        elif isinstance(message, _RedisResponse):
            # TODO(tailhook) check error
            FUTURES[message.future_id].set_result(message.value)
        else:
            loop.create_task(callback(loop, message))


def start(callback, *, loop=None):
    global LOOP
    if loop is None:
        loop = asyncio.get_event_loop()
    LOOP = loop
    assert asyncio.iscoroutinefunction(callback), callback

# Path: stator/loop.py
# def parse_message(self, input):
#     raise RuntimeError("abstract method")
# 
# @_skip
# def blocking_io():
#     return False
# 
# class Socket(object):
# 
#     def __init__(self, id):
#         assert isinstance(id, INT_TYPES), (type(id), id)
#         self.id = id
#         TABLE.add(self)
# 
#     def close(self):
#         TABLE.remove(self.id)
# 
#     def parse_message(self, input):
#         raise RuntimeError("abstract method")
# 
#     def __repr__(self):
#         return '<{} {}>'.format(self.__class__.__name__,
#             repr(self.__dict__)[1:-1])
# 
# Path: stator/lib.py



# Path: stator/aio.py
import asyncio
import cbor
from collections import namedtuple
from functools import partial
from .loop import parse_message, blocking_io, Socket
from .lib import dll
from . import redis

        return f

    def parse_message(self, input):
        req_id = cbor.load(input)
        data = cbor.load(input)
        return _RedisResponse(req_id, data)


def dispatch_messages(loop, callback):
    while True:
        message = dll.stator_next_message(parse_message, blocking_io)
        if message is False:
            break
        elif message is None:
            continue
        elif isinstance(message, BaseException):
            raise message
        elif isinstance(message, _RedisResponse):
            # TODO(tailhook) check error
            FUTURES[message.future_id].set_result(message.value)
        else:
            loop.create_task(callback(loop, message))


def start(callback, *, loop=None):
    global LOOP
    if loop is None:
        loop = asyncio.get_event_loop()
    LOOP = loop
    assert asyncio.iscoroutinefunction(callback), callback

    loop.add_reader(dll.stator_get_input_fd(),