浏览代码

change _abort method logic: firstly emit error message, then destory/disconnect

afrokick 5 年之前
父节点
当前提交
173b58a012
共有 1 个文件被更改,包括 3 次插入3 次删除
  1. 3 3
      lib/peer.ts

+ 3 - 3
lib/peer.ts

@@ -441,20 +441,20 @@ export class Peer extends EventEmitter {
   }
   }
 
 
   /**
   /**
-   * Destroys the Peer and emits an error message.
+   * Emits an error message and destroys the Peer.
    * The Peer is not destroyed if it's in a disconnected state, in which case
    * The Peer is not destroyed if it's in a disconnected state, in which case
    * it retains its disconnected state and its existing connections.
    * it retains its disconnected state and its existing connections.
    */
    */
   private _abort(type: PeerErrorType, message): void {
   private _abort(type: PeerErrorType, message): void {
     logger.error("Aborting!");
     logger.error("Aborting!");
 
 
+    this.emitError(type, message);
+
     if (!this._lastServerId) {
     if (!this._lastServerId) {
       this.destroy();
       this.destroy();
     } else {
     } else {
       this.disconnect();
       this.disconnect();
     }
     }
-
-    this.emitError(type, message);
   }
   }
 
 
   /** Emits a typed error message. */
   /** Emits a typed error message. */