File tree 3 files changed +28
-2
lines changed
3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 3
3
var ZongJi = require ( 'zongji' ) ;
4
4
var mysql = require ( 'mysql' ) ;
5
5
6
+ // Maximum duration to wait for Zongji to initialize before timeout error (ms)
7
+ var ZONGJI_INIT_TIMEOUT = 1500 ;
8
+
6
9
var LiveMysqlSelect = require ( './LiveMysqlSelect' ) ;
7
10
8
11
function LiveMysql ( settings , callback ) {
@@ -63,8 +66,24 @@ function LiveMysql(settings, callback){
63
66
64
67
} ) ;
65
68
69
+ // Wait for Zongji to be ready before executing callback
70
+ var zongjiInitTime = Date . now ( ) ;
71
+ var zongjiReady = function ( ) {
72
+ if ( zongji . ready === true ) {
73
+ // Call the callback if it exists and do not keep waiting
74
+ callback && callback ( ) ;
75
+ } else {
76
+ // Wait for Zongji to be ready
77
+ if ( Date . now ( ) - zongjiInitTime > ZONGJI_INIT_TIMEOUT ) {
78
+ // Zongji initialization has exceeded timeout, callback error
79
+ callback && callback ( new Error ( 'ZONGJI_INIT_TIMEOUT_OCCURED' ) ) ;
80
+ } else {
81
+ setTimeout ( zongjiReady , 40 ) ;
82
+ }
83
+ }
84
+ } ;
66
85
zongji . start ( self . zongjiSettings ) ;
67
- if ( callback ) return callback ( ) ;
86
+ zongjiReady ( ) ;
68
87
} ) ;
69
88
}
70
89
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " mysql-live-select" ,
3
- "version" : " 0.0.21 " ,
3
+ "version" : " 0.0.22 " ,
4
4
"description" : " Live updating MySQL SELECT statements" ,
5
5
"main" : " lib/LiveMysql.js" ,
6
6
"repository" : " https://github.com/numtel/mysql-live-select" ,
Original file line number Diff line number Diff line change @@ -242,6 +242,13 @@ module.exports = {
242
242
} ) ;
243
243
} ) ;
244
244
} ,
245
+ immediate_disconnection : function ( test ) {
246
+ var myTest = new LiveMysql ( settings , function ( error ) {
247
+ myTest . end ( ) ;
248
+ test . ok ( typeof error === 'undefined' ) ;
249
+ test . done ( ) ;
250
+ } ) ;
251
+ } ,
245
252
error_invalid_connection : function ( test ) {
246
253
var myTest = new LiveMysql ( {
247
254
host : '127.0.0.1' ,
You can’t perform that action at this time.
0 commit comments