# Error code E0728

`await` has been used outside `async` function or `async` block.

Erroneous code example:

ⓘ

    fn foo() {
        wake_and_yield_once().await // `await` is used outside `async` context
    }

Run

`await` is used to suspend the current computation until the given future is ready to produce a value. So it is legal only within an `async` context, like an `async` function or an `async` block.

ⓘ

    async fn foo() {
        wake_and_yield_once().await // `await` is used within `async` function
    }

    fn bar(x: u8) -> impl Future<Output = u8> {
        async move {
            wake_and_yield_once().await; // `await` is used within `async` block
            x
        }
    }

Run

Back to list of error codes