async function settled(promises) {
        let firstError = undefined;
        const result = await Promise.all(promises.map(promise => promise.then(value => value, error => {
            if (!firstError) {
                firstError = error;
            }
            return undefined; // do not rethrow so that other promises can settle
        })));
        if (typeof firstError !== 'undefined') {
            throw firstError;
        }
        return result; // cast is needed and protected by the `throw` above
    }
A drop-in replacement for `Promise.all` with the only difference
that the method awaits every promise to either fulfill or reject.

Similar to `Promise.all`, only the first error will be returned
if any.