'Add a recv event, returning the corresponding Future'

def _add_recv_event(self, kind, kwargs=None, future=None):

    f = (future or self._Future())
    if (kind.startswith('recv') and (kwargs.get('flags', 0) & _zmq.DONTWAIT)):
        recv = getattr(self._shadow_sock, kind)
        try:
            r = recv(**kwargs)
        except Exception as e:
            f.set_exception(e)
        else:
            f.set_result(r)
        return f
    self._recv_futures.append(_FutureEvent(f, kind, kwargs, msg=None))
    f.add_done_callback((lambda f: self._remove_finished_future(f, self._recv_futures)))
    if hasattr(_zmq, 'RCVTIMEO'):
        timeout_ms = self._shadow_sock.rcvtimeo
        if (timeout_ms >= 0):
            self._add_timeout(f, (timeout_ms * 0.001))
    if (self._shadow_sock.EVENTS & POLLIN):
        self._handle_recv()
    if self._recv_futures:
        self._add_io_state(POLLIN)
    return f
