Skip to content

Commit 9088407

Browse files
committed
Use the error-first callback for getPorts() and getBaudRates()
1 parent 2fdc791 commit 9088407

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Controller.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Controller {
209209
// @param {string} options.host `socket` The host address to connect.
210210
// @param {number} [options.port=23] `socket` The port number.
211211
// @param {function} [callback] Called after a connection is opened.
212-
open(controllerType, connectionType, options, callback) {
212+
open(controllerType, connectionType, options, callback = noop) {
213213
if (typeof options !== 'object') {
214214
options = {};
215215
callback = options;
@@ -230,7 +230,7 @@ class Controller {
230230
}
231231
// Closes an open connection.
232232
// @param {function} [callback] Called once a connection is closed.
233-
close(callback) {
233+
close(callback = noop) {
234234
if (typeof callback !== 'function') {
235235
callback = noop;
236236
}
@@ -325,17 +325,25 @@ class Controller {
325325
this.socket.emit('writeln', this.connection.ident, data, context);
326326
}
327327
// Gets a list of available serial ports.
328-
// @param {function} [callback] Called once completed.
329-
getPorts(callback) {
328+
// @param {function} [callback] The error-first callback.
329+
getPorts(callback = noop) {
330+
if (typeof callback !== 'function') {
331+
callback = noop;
332+
}
330333
if (!this.socket) {
334+
callback(new Error('The socket is not connected'));
331335
return;
332336
}
333337
this.socket.emit('getPorts', callback);
334338
}
335339
// Gets a list of supported baud rates.
336-
// @param {function} [callback] Called once completed.
337-
getBaudRates(callback) {
340+
// @param {function} [callback] The error-first callback.
341+
getBaudRates(callback = noop) {
342+
if (typeof callback !== 'function') {
343+
callback = noop;
344+
}
338345
if (!this.socket) {
346+
callback(new Error('The socket is not connected'));
339347
return;
340348
}
341349
this.socket.emit('getBaudRates', callback);

0 commit comments

Comments
 (0)