Page Contents
Home > @loopback/context > resolveList
resolveList() function
Resolve entries of an array into a new array with the same indexes. If one or more entries of the source array are resolved to a promise by the resolver
function, this method returns a promise which will be resolved to the new array with fully resolved entries.
Signature:
export declare function resolveList<T, V>(list: T[], resolver: (val: T, index: number, values: T[]) => ValueOrPromise<V>): ValueOrPromise<V[]>;
Parameters
Parameter | Type | Description |
---|---|---|
list | T[] | The original array containing the source entries |
resolver | (val: T, index: number, values: T[]) => ValueOrPromise<V> | A function resolves an entry to a value or promise. It will be invoked with the property value, the property index, and the source array. |
Returns:
ValueOrPromise<V[]>
Example
- Example 1: resolve all entries synchronously
const result = resolveList(['a', 'b'], v => v.toUpperCase());
The result
will be ['A', 'B']
.
- Example 2: resolve one or more entries asynchronously
const result = resolveList(['a', 'b'], v =>
Promise.resolve(v.toUpperCase()),
);
The result
will be a promise of ['A', 'B']
.