@@ -11,69 +11,69 @@ const Option = require('./Option')
11
11
* Expose Asynchronous Option.
12
12
*/
13
13
14
- class AsyncOption extends Option { }
14
+ class AsyncOption extends Option {
15
+ /**
16
+ * Asynchronous serial running
17
+ * @param args
18
+ * @param {Array<AsyncFunction> } args
19
+ */
15
20
16
- /**
17
- * Asynchronous serial running
18
- * @param args
19
- * @param {Array<AsyncFunction> } args
20
- */
21
-
22
- AsyncOption . prototype . asyncApply = async function ( ...args ) {
23
- const items = [ ]
24
- for ( const { name, value } of this . items ) {
25
- try {
26
- items . push ( {
27
- name,
28
- value : isFunction ( value )
29
- ? await value ( ...args )
30
- : value
31
- } )
32
- } catch ( error ) {
33
- logger . error ( `${ chalk . cyan ( name ) } apply ${ chalk . cyan ( this . key ) } failed.` )
34
- throw error
21
+ async asyncApply ( ...args ) {
22
+ const items = [ ]
23
+ for ( const { name, value } of this . items ) {
24
+ try {
25
+ items . push ( {
26
+ name,
27
+ value : isFunction ( value )
28
+ ? await value ( ...args )
29
+ : value
30
+ } )
31
+ } catch ( error ) {
32
+ logger . error ( `${ chalk . cyan ( name ) } apply ${ chalk . cyan ( this . key ) } failed.` )
33
+ throw error
34
+ }
35
35
}
36
+ this . appliedItems = items
36
37
}
37
- this . appliedItems = items
38
- }
39
38
40
- /**
41
- * Asynchronous serial running
42
- * @param args
43
- * @param {Array<AsyncFunction> } args
44
- */
39
+ /**
40
+ * Asynchronous serial running
41
+ * @param args
42
+ * @param {Array<AsyncFunction> } args
43
+ */
45
44
46
- AsyncOption . prototype . parallelApply = async function ( ...args ) {
47
- const items = [ ]
48
- await Promise . all ( this . items . map ( async ( { name, value } ) => {
49
- try {
50
- items . push ( {
51
- name,
52
- value : isFunction ( value )
53
- ? await value ( ...args )
54
- : value
55
- } )
56
- } catch ( error ) {
57
- logger . error ( `${ chalk . cyan ( name ) } apply ${ chalk . cyan ( this . key ) } failed.` )
45
+ async parallelApply ( ...args ) {
46
+ const items = [ ]
47
+ await Promise . all ( this . items . map ( async ( { name, value } ) => {
48
+ try {
49
+ items . push ( {
50
+ name,
51
+ value : isFunction ( value )
52
+ ? await value ( ...args )
53
+ : value
54
+ } )
55
+ } catch ( error ) {
56
+ logger . error ( `${ chalk . cyan ( name ) } apply ${ chalk . cyan ( this . key ) } failed.` )
57
+ throw error
58
+ }
59
+ } ) ) . catch ( error => {
58
60
throw error
59
- }
60
- } ) ) . catch ( error => {
61
- throw error
62
- } )
63
- return items
64
- }
61
+ } )
62
+ return items
63
+ }
65
64
66
- /**
67
- * Process a value via a pipeline.
68
- * @param input
69
- * @returns {* }
70
- */
65
+ /**
66
+ * Process a value via a pipeline.
67
+ * @param input
68
+ * @returns {* }
69
+ */
71
70
72
- AsyncOption . prototype . pipeline = async function ( input ) {
73
- for ( const fn of this . values ) {
74
- input = await fn ( input )
71
+ async pipeline ( input ) {
72
+ for ( const fn of this . values ) {
73
+ input = await fn ( input )
74
+ }
75
+ return input
75
76
}
76
- return input
77
77
}
78
78
79
79
AsyncOption . prototype . apply = AsyncOption . prototype . asyncApply
0 commit comments