@@ -14,39 +14,41 @@ export default {
14
14
/**
15
15
* Start the spinner with the given message
16
16
*/
17
- start ( msg : string , id ?: string ) {
18
- queue ( 'start' , msg , id ) ;
17
+ async start ( msg : string , id ?: string ) {
18
+ await queue ( 'start' , msg , id ) ;
19
19
} ,
20
20
/**
21
21
* Stop the spinner, replace the spinner graphic with a checkmark, optionally update the message,
22
22
* and turn it green.
23
23
*/
24
- succeed ( msg ?: string , id ?: string ) {
25
- queue ( 'succeed' , msg , id ) ;
24
+ async succeed ( msg ?: string , id ?: string ) {
25
+ await queue ( 'succeed' , msg , id ) ;
26
26
} ,
27
27
/**
28
28
* Stop the spinner, replace the spinner graphic with an X, optionally update the message, and
29
29
* turn it red.
30
30
*/
31
- fail ( msg ?: string , id ?: string ) {
32
- queue ( 'fail' , msg , id ) ;
31
+ async fail ( msg ?: string , id ?: string ) {
32
+ await queue ( 'fail' , msg , id ) ;
33
33
} ,
34
34
/**
35
35
* Stop the spinner, replace the spinner graphic with the supplied symbol and message with the
36
36
* supplied text.
37
37
*/
38
- finish ( symbol : string , text : string , id ?: string ) {
39
- queue ( 'finish' , symbol , text , id ) ;
38
+ async finish ( symbol : string , text : string , id ?: string ) {
39
+ await queue ( 'finish' , symbol , text , id ) ;
40
40
}
41
41
} ;
42
42
43
- let operationsQueue : { operation : string , args : any [ ] } [ ] = [ ] ;
43
+ let operationsQueue : { operation : string , args : any [ ] , done ( ) : void } [ ] = [ ] ;
44
44
let inFlight = false ;
45
45
let spinnerIsActive = false ;
46
46
47
- function queue ( operation : string , ...args : any [ ] ) : void {
48
- operationsQueue . push ( { operation, args } ) ;
49
- flushQueue ( ) ;
47
+ async function queue ( operation : string , ...args : any [ ] ) : Promise < void > {
48
+ return new Promise < void > ( ( done ) => {
49
+ operationsQueue . push ( { done, operation, args } ) ;
50
+ flushQueue ( ) ;
51
+ } ) ;
50
52
}
51
53
52
54
function flushQueue ( ) {
@@ -67,6 +69,7 @@ function flushQueue() {
67
69
if ( nextOperation . operation !== 'start' ) {
68
70
spinnerIsActive = false ;
69
71
}
72
+ nextOperation . done ( ) ;
70
73
flushQueue ( ) ;
71
74
} ) ;
72
75
}
0 commit comments