Skip to content

Commit 76462dd

Browse files
committed
Exposed port configuration in types.
Removed superfluous stop checks.
1 parent 3c56942 commit 76462dd

File tree

2 files changed

+29
-34
lines changed

2 files changed

+29
-34
lines changed

index.js

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ ZongJi.prototype.start = function (options = {}) {
192192
this._options(options);
193193
this._filters(options);
194194

195-
// Don't start listener if it has already explicitly been stopped
196-
if (this.stopped) {
197-
return;
198-
}
199195
const testChecksum = (resolve, reject) => {
200196
this._isChecksumEnabled((err, checksumEnabled) => {
201197
if (err) {
@@ -258,41 +254,38 @@ ZongJi.prototype.start = function (options = {}) {
258254
this.emit('binlog', event);
259255
};
260256

261-
if (!this.stopped) {
262-
let promises = [new Promise(testChecksum)];
257+
let promises = [new Promise(testChecksum)];
263258

264-
if (this.options.startAtEnd) {
265-
promises.push(new Promise(findBinlogEnd));
266-
}
267-
268-
Promise.all(promises)
269-
.then(() => {
270-
this.BinlogClass = initBinlogClass(this);
271-
if (!this.stopped) {
272-
this.connection._protocol._enqueue(new this.BinlogClass(binlogHandler));
273-
this.ready = true;
274-
this.emit('ready');
275-
}
276-
})
277-
.catch((err) => {
278-
// Don't emit errors if the listener is already stopped
279-
if (!this.stopped) {
280-
this.emit('error', err);
281-
}
282-
});
259+
if (this.options.startAtEnd) {
260+
promises.push(new Promise(findBinlogEnd));
283261
}
262+
263+
Promise.all(promises)
264+
.then(() => {
265+
this.BinlogClass = initBinlogClass(this);
266+
if (!this.stopped) {
267+
this.connection._protocol._enqueue(new this.BinlogClass(binlogHandler));
268+
this.ready = true;
269+
this.emit('ready');
270+
}
271+
})
272+
.catch((err) => {
273+
this.emit('error', err);
274+
});
284275
};
285276

286277
ZongJi.prototype.stop = function () {
287-
// Binary log connection does not end with destroy()
288-
this.connection.destroy();
289-
this.ctrlConnection.query('KILL ' + this.connection.threadId, () => {
290-
if (this.ctrlConnectionOwner) {
291-
this.ctrlConnection.destroy();
292-
}
293-
this.emit('stopped');
294-
});
295-
this.stopped = true;
278+
if (!this.stopped) {
279+
this.stopped = true;
280+
// Binary log connection does not end with destroy()
281+
this.connection.destroy();
282+
this.ctrlConnection.query('KILL ' + this.connection.threadId, () => {
283+
if (this.ctrlConnectionOwner) {
284+
this.ctrlConnection.destroy();
285+
}
286+
this.emit('stopped');
287+
});
288+
}
296289
};
297290

298291
ZongJi.prototype.pause = function () {

types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Socket } from 'net';
1111
*/
1212
export type ZongjiOptions = {
1313
host: string;
14+
port?: number;
1415
user: string;
1516
password: string;
1617
dateStrings?: boolean;
@@ -168,6 +169,7 @@ export interface MySQLConnection {
168169
}
169170

170171
export declare class ZongJi {
172+
stopped: boolean;
171173
connection: MySQLConnection;
172174
constructor(options: ZongjiOptions);
173175

0 commit comments

Comments
 (0)