'Return a Future for a poll event'

def poll(self, timeout=(-1)):

    future = self._Future()
    if (timeout == 0):
        try:
            result = super(_AsyncPoller, self).poll(0)
        except Exception as e:
            future.set_exception(e)
        else:
            future.set_result(result)
        return future
    loop = self._default_loop()
    watcher = self._Future()
    raw_sockets = []
    def wake_raw(*args):
        if (not watcher.done()):
            watcher.set_result(None)
    watcher.add_done_callback((lambda f: self._unwatch_raw_sockets(loop, *raw_sockets)))
    for (socket, mask) in self.sockets:
        if isinstance(socket, _zmq.Socket):
            if (not isinstance(socket, self._socket_class)):
                socket = self._socket_class.from_socket(socket)
            if (mask & _zmq.POLLIN):
                socket._add_recv_event('poll', future=watcher)
            if (mask & _zmq.POLLOUT):
                socket._add_send_event('poll', future=watcher)
        else:
            raw_sockets.append(socket)
            evt = 0
            if (mask & _zmq.POLLIN):
                evt |= self._READ
            if (mask & _zmq.POLLOUT):
                evt |= self._WRITE
            self._watch_raw_socket(loop, socket, evt, wake_raw)
    def on_poll_ready(f):
        if future.done():
            return
        if watcher.exception():
            future.set_exception(watcher.exception())
        else:
            try:
                result = super(_AsyncPoller, self).poll(0)
            except Exception as e:
                future.set_exception(e)
            else:
                future.set_result(result)
    watcher.add_done_callback(on_poll_ready)
    if ((timeout is not None) and (timeout > 0)):
        def trigger_timeout():
            if (not watcher.done()):
                watcher.set_result(None)
        timeout_handle = loop.call_later((0.001 * timeout), trigger_timeout)
        def cancel_timeout(f):
            if hasattr(timeout_handle, 'cancel'):
                timeout_handle.cancel()
            else:
                loop.remove_timeout(timeout_handle)
        future.add_done_callback(cancel_timeout)
    def cancel_watcher(f):
        if (not watcher.done()):
            watcher.cancel()
    future.add_done_callback(cancel_watcher)
    return future
