diff --git a/packages/binding-coap/src/coap-server.ts b/packages/binding-coap/src/coap-server.ts index 52969f88c..88d9d8b1a 100644 --- a/packages/binding-coap/src/coap-server.ts +++ b/packages/binding-coap/src/coap-server.ts @@ -194,25 +194,21 @@ export default class CoapServer implements ProtocolServer { }); } - public destroy(thingId: string): Promise { + public async destroy(thingId: string): Promise { debug(`CoapServer on port ${this.getPort()} destroying thingId '${thingId}'`); - return new Promise((resolve, reject) => { - let removedThing: ExposedThing; - for (const name of Array.from(this.things.keys())) { - const expThing = this.things.get(name); - if (expThing?.id === thingId) { - this.things.delete(name); - this.coreResources.delete(name); - removedThing = expThing; - } - } - if (removedThing) { - info(`CoapServer succesfully destroyed '${removedThing.title}'`); - } else { - info(`CoapServer failed to destroy thing with thingId '${thingId}'`); + for (const name of Array.from(this.things.keys())) { + const expThing = this.things.get(name); + if (expThing?.id === thingId) { + this.things.delete(name); + this.coreResources.delete(name); + + info(`CoapServer succesfully destroyed '${expThing.title}'`); + return true; } - resolve(removedThing !== undefined); - }); + } + + info(`CoapServer failed to destroy thing with thingId '${thingId}'`); + return false; } private formatCoreLinkFormatResources() {