Skip to content

Commit

Permalink
Add .disconnect() to MessageBuses
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Jun 1, 2023
1 parent 1cd734a commit 1038931
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ module.exports = function bus(conn, opts) {
this.signals = new EventEmitter();
this.exportedObjects = {};

this.disconnect = function () {
if (// Some of these might be redundant, but best to check everything explicitly:
conn.writableEnded ||
conn.readableEnded ||
conn.closed ||
conn.destroyed ||
conn.errored
) {
return Promise.resolve();
}

return new Promise(function (resolve, reject) {
conn.on('end', resolve);
conn.on('error', reject);
conn.end();
});
};

this.invoke = promisify(function(msg, callback) {
if (!msg.type) msg.type = constants.messageType.methodCall;
msg.serial = self.serial++;
Expand Down
1 change: 1 addition & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function createClient(options: {

export interface DBusClient {
getService(name: string): DBusService;
disconnect(): Promise<void>;
}

export interface DBusService {
Expand Down

0 comments on commit 1038931

Please sign in to comment.