[][src]Struct rslint_core::groups::errors::NoAwaitInLoop

pub struct NoAwaitInLoop {}

Disallow await inside of loops.

You may want to await a promise until it is fulfilled or rejected, inside of loops. In such cases, to take full advantage of concurrency, you should not await the promise in every iteration, otherwise your async operations will be executed serially. Generally it is recommended that you create all promises, then use Promise.all for them. This way your async operations will be performed concurrently.

Incorrect Code Exapmles

async function foo(xs) {
    const results = [];
    for (const x of xs) {
        // iteration does not proceed until `bar(x)` completes
        results.push(await bar(x));
    }
    return baz(results);
}

Correct Code Examples

async function foo(xs) {
    const results = [];
    for (const x of xs) {
        // push a promise to the array; it does not prevent the iteration
        results.push(bar(x));
    }
    // we wait for all the promises concurrently
    return baz(await Promise.all(results));
}

Implementations

impl NoAwaitInLoop[src]

pub fn new() -> Self[src]

Trait Implementations

impl Clone for NoAwaitInLoop[src]

impl CstRule for NoAwaitInLoop[src]

impl Debug for NoAwaitInLoop[src]

impl Default for NoAwaitInLoop[src]

impl<'de> Deserialize<'de> for NoAwaitInLoop[src]

impl Rule for NoAwaitInLoop[src]

impl Serialize for NoAwaitInLoop[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> DynClone for T where
    T: Clone
[src]

impl<T> Erasable for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Serialize for T where
    T: Serialize + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.