@@ -7,19 +7,21 @@ function zongjiManager(dsn, options, onBinlog) {
7
7
var newInst = new ZongJi ( dsn , options ) ;
8
8
newInst . on ( 'error' , function ( reason ) {
9
9
newInst . removeListener ( 'binlog' , onBinlog ) ;
10
- setTimeout ( function ( ) {
11
- // If multiple errors happened, a new instance may have already been created
12
- if ( ! ( 'child' in newInst ) ) {
13
- newInst . child = zongjiManager ( dsn , Object . assign ( { } , options , newInst . binlogNextPos
14
- ? { binlogName : newInst . binlogName ,
10
+ newInst . child = false ;
11
+ setTimeout ( function ( ) {
12
+ // If multiple errors happened, a new instance may have already been created
13
+ if ( ! newInst . child ) {
14
+ var newInstNext = zongjiManager ( dsn , Object . assign ( { } , options , newInst . binlogNextPos
15
+ ? { binlogName : newInst . binlogName ,
15
16
binlogNextPos : newInst . binlogNextPos
16
- }
17
- : { }
18
- ) , onBinlog ) ;
19
- newInst . emit ( 'child' , newInst . child , reason ) ;
20
- newInst . child . on ( 'child' , child => newInst . emit ( 'child' , child ) ) ;
21
- }
22
- } , RETRY_TIMEOUT ) ;
17
+ }
18
+ : { }
19
+ ) , onBinlog ) ;
20
+ newInst . stop ( ) ;
21
+ newInst = newInstNext ;
22
+ newInst . child = true ;
23
+ }
24
+ } , RETRY_TIMEOUT ) ;
23
25
} ) ;
24
26
newInst . on ( 'binlog' , onBinlog ) ;
25
27
newInst . start ( options ) ;
0 commit comments