'Add a send event, returning the corresponding Future'

def _add_send_event(self, kind, msg=None, kwargs=None, future=None):

    f = (future or self._Future())
    if (kind.startswith('send') and (kwargs.get('flags', 0) & _zmq.DONTWAIT)):
        send = getattr(self._shadow_sock, kind)
        try:
            r = send(msg, **kwargs)
        except Exception as e:
            f.set_exception(e)
        else:
            f.set_result(r)
        return f
    self._send_futures.append(_FutureEvent(f, kind, kwargs=kwargs, msg=msg))
    f.add_done_callback((lambda f: self._remove_finished_future(f, self._send_futures)))
    if hasattr(_zmq, 'SNDTIMEO'):
        timeout_ms = self._shadow_sock.sndtimeo
        if (timeout_ms >= 0):
            self._add_timeout(f, (timeout_ms * 0.001))
    if (self._shadow_sock.EVENTS & POLLOUT):
        self._handle_send()
    if self._send_futures:
        self._add_io_state(POLLOUT)
    return f
