@@ -19,14 +19,14 @@ export default class EnterpriseMaintenanceManager extends EventEmitter {
19
19
20
20
// Queue:
21
21
// toWrite [ C D E ]
22
- // waitingForReply [ A B ]
22
+ // waitingForReply [ A B ] - aka In-flight commands
23
23
//
24
24
// time: ---1-2---3-4-5-6---------------------------
25
25
//
26
26
// 1. [EVENT] MOVING PN received
27
27
// 2. [ACTION] Pause writing ( we need to wait for new socket to connect and for all in-flight commands to complete )
28
28
// 3. [EVENT] New socket connected
29
- // 4. [EVENT] WaitingForReply commands completed
29
+ // 4. [EVENT] In-flight commands completed
30
30
// 5. [ACTION] Destroy old socket
31
31
// 6. [ACTION] Resume writing -> we are going to write to the new socket from now on
32
32
#onMoving = async (
@@ -46,17 +46,8 @@ export default class EnterpriseMaintenanceManager extends EventEmitter {
46
46
await newSocket . connect ( ) ;
47
47
// 3 [EVENT] New socket connected
48
48
49
- // Wait until waitingForReply is empty
50
- await new Promise < void > ( ( resolve ) => {
51
- if ( ! this . commandsQueue . isWaitingForReply ( ) ) {
52
- resolve ( ) ;
53
- } else {
54
- this . commandsQueue . events . once ( "waitingForReplyEmpty" , ( ) => {
55
- resolve ( ) ;
56
- } ) ;
57
- }
58
- } ) ;
59
- // 4 [EVENT] WaitingForReply commands completed
49
+ await this . commandsQueue . waitForInflightCommandsToComplete ( ) ;
50
+ // 4 [EVENT] In-flight commands completed
60
51
61
52
// 5 + 6
62
53
this . emit ( 'resume' , newSocket ) ;
0 commit comments