destroy method
关闭连接销毁实例,调用此函数后,此实例不可进行websocket网络操作,不可重新连接网络。
Implementation
Future<void> destroy() async {
if (_expired) return;
logDebug(['destroy...']);
//关闭计时器
_timer?.cancel();
_timer = null;
//清除监听器
_requesterMap.clear();
_listenersMap.clear();
//安全关闭连接
_safeClose(EasyConstant.clientCloseByDestroy.code, EasyConstant.clientCloseByDestroy.desc);
//销毁隔离线程
await _thread?.close();
//最后设置废弃标志
return Future.delayed(Duration(milliseconds: 30), () {
_expired = true;
logInfo(['destroyed.']);
});
}