(error_queue: ErrorQueueType, co)
Cancel the provided coroutine if an error appears on the error queue

    If no error appears on the queue, then the result of the
    coroutine will be returned.

    If an error does appear then the error will be raised
Cancel the provided coroutine if an error appears on the error queue
Cancel the provided coroutine if an error appears on the error queue
async def bail_on_error(error_queue: ErrorQueueType, co):
    """Cancel the provided coroutine if an error appears on the error queue

    If no error appears on the queue, then the result of the
    coroutine will be returned.

    If an error does appear then the error will be raised
    """

    assert iscoroutine(co), "@bail_on_error only operates on coroutines"
    fn_task = asyncio.ensure_future(co)
    monitor_task = asyncio.ensure_future(error_queue.get())

    done, pending = await asyncio.wait({fn_task, monitor_task}, return_when=asyncio.FIRST_COMPLETED)

    if fn_task in done:
        # All ok
        await cancel(monitor_task)
        return fn_task.result()
    else:
        # An error appeared in the queue
        await cancel(fn_task)
        error: Error = monitor_task.result()
        # Put the error back on the queue so it can be picked up
        # by the bus client
        error_queue.put_nowait(error)
        raise error.value
async def bail_on_error ( error_queue : ErrorQueueType , co ) : assert iscoroutine ( co ) , "@bail_on_error only operates on coroutines" fn_task = asyncio . ensure_future ( co ) monitor_task = asyncio . ensure_future ( error_queue . get ( ) ) done , pending = await asyncio . wait ( { fn_task , monitor_task } , return_when = asyncio . FIRST_COMPLETED ) if fn_task in done : # All ok await cancel ( monitor_task ) return fn_task . result ( ) else : # An error appeared in the queue await cancel ( fn_task ) error : Error = monitor_task . result ( ) # Put the error back on the queue so it can be picked up # by the bus client error_queue . put_nowait ( error ) raise error . value