From e53b4eadda3b0004c9f07741ed994872d98ad24f Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 26 Nov 2022 17:27:35 -0500 Subject: [PATCH] *Check if we are bootstrapped and queue broadcast in removeItem like with addItem --- src/index.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 46fb16e..943360b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -136,11 +136,19 @@ export default class DHTCache extends EventEmitter { this._removeEntity(item); - this._broadcastMessage({ - type: Type.REMOVE_ITEM, - data: b4a.from(item, "hex"), - signature: this._signItem(item), - }); + const broadcast = () => { + this._broadcastMessage({ + type: Type.REMOVE_ITEM, + data: b4a.from(item as string, "hex"), + signature: this._signItem(item), + }); + }; + + if (!this.bootstrapped) { + this.once("bootstrapped", broadcast); + } else { + broadcast(); + } return true; }