What is ReflectAll(tasks) in Async?

Async is a utility module that provides powerful, straight-forward functions for working with asynchronous JavaScript.

Async reflectAll

**Async reflectAll** is a helper function that wraps an array or an object of functions with [async reflect](https://how.dev/answers/how-to-use-the-reflect-function-in-javascripts-async-module). It returns a type array of async functions that are each wrapped in `async.reflect`. `Reflect` is useful as it wraps any async function in another function and always results a return object. If there is an error, the result object will return a NULL value.

Key features

1. It is a static method. 2. It is a member of `module:utils`. 3. The parameters are collections of async functions of type `Array|Object|Iterable` tasks. 4. It returns an array of async functions that are each wrapped in `async.reflect`.

Sample Code

The default code for this method is reflectAll:

export default function
// tasks is the parameters
reflectAll(tasks) {
    var results;
// if it's an array, simply perform reflect on the whole array
    if (Array.isArray(tasks)) {
        results = tasks.map(reflect);
    } else {
// otherwise, call reflect individually on each task and store it in an array
        results = {};
        Object.keys(tasks).forEach(key => {
            results[key] = reflect.call(this, tasks[key]);
        });
    }
    return results;
}

For more information, click here.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved