Failed Conditions
Push — master ( f5e7b3...711045 )
by Yo
01:30
created

lib/plugins/promise/seqAnyway.js   A

Complexity

Total Complexity 4
Complexity/F 1.33

Size

Lines of Code 27
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 27
rs 10
wmc 4
mnd 1
bc 5
fnc 3
bpm 1.6666
cpm 1.3333
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A seqAnyway.js ➔ ??? 0 16 1
1
"use strict";
2
3
/**
4
 * @param {Array<callback>} callbackList
5
 *
6
 * @returns {Promise<value>} Return a promise resolved even if one or more callbacks have failed.
7
 *                           Callbacks will be called one by one in the order returned by callbackList.map
8
 *                           Resolved value is an object containing resolvedList and rejectedList
9
 *                            - resolvedList will contains successful callback returned value ordered by callback index
10
 *                            - rejectedList will contains rejected callback error ordered by callback index
11
 */
12
module.exports = (callbackList) => {
13
    const resolvedList = [];
14
    const rejectedList = [];
15
16
    return new Promise(resolve => {
17
        callbackList.map((callback, index) => {
18
            try {
19
                resolvedList[index] = callback();
20
            } catch (e) {
21
                rejectedList[index] = e;
22
            }
23
        });
24
25
        resolve({resolvedList, rejectedList});
26
    });
27
};
28