Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
milesstoetzner committed Sep 22, 2023
1 parent 52cc3b5 commit be46338
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/target/mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as assert from '#assert'
import * as check from '#check'
import Message from '#core/message'
import std from '#std'
import hae from '#utils/hae'
import * as mqtt from 'mqtt'

export type MQTTTargetOptions = {
Expand Down Expand Up @@ -73,7 +74,9 @@ export class MQTTTarget extends Target {

async stop() {
std.log('stopping mqtt target')
if (check.isDefined(this.target)) await this.target.endAsync()
await hae.try(async () => {
if (check.isDefined(this.target)) await this.target.endAsync()
}, 'problem when stopping mqtt target')
std.log('mqtt target stopped')
}
}
5 changes: 4 additions & 1 deletion src/target/socketio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as assert from '#assert'
import * as check from '#check'
import Message, {JSONMessage} from '#core/message'
import std from '#std'
import hae from '#utils/hae'
import SocketIOClient, {Socket} from 'socket.io-client'

export type SocketIOTargetOptions = {
Expand Down Expand Up @@ -62,7 +63,9 @@ export class SocketIOTarget extends Target {
async stop() {
// TODO: wait for disconnect
std.log('stopping socketio target')
if (check.isDefined(this.target)) this.target.disconnect()
await hae.try(async () => {
if (check.isDefined(this.target)) this.target.disconnect()
}, 'problem when stopping socketio target')
std.log('socketio target stopped')
}
}
5 changes: 4 additions & 1 deletion src/target/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as assert from '#assert'
import * as check from '#check'
import Message from '#core/message'
import std from '#std'
import hae from '#utils/hae'
import WebSocket from 'ws'

export type WSTargetOptions = {
Expand Down Expand Up @@ -57,7 +58,9 @@ export class WSTarget extends Target {
async stop() {
// TODO: wait for disconnect
std.log('stopping websocket target')
if (check.isDefined(this.target)) this.target.close()
await hae.try(async () => {
if (check.isDefined(this.target)) this.target.close()
}, 'problem when stopping websocket target')
std.log('websocket target stopped')
}
}

0 comments on commit be46338

Please sign in to comment.