- setTimeout(() => {
- this.deleteResponseHandler(uuid);
- return reject(new Error(`Send request '${command}' message timeout`));
- }, 60 * 1000);
- this.ws.send(msg);
+ const uuid = crypto.randomUUID()
+ const msg = JSON.stringify([uuid, command, data])
+ const sendTimeout = setTimeout(() => {
+ this.deleteResponseHandler(uuid)
+ return reject(new Error(`Send request '${command}' message timeout`))
+ }, 60 * 1000)
+ try {
+ this.ws.send(msg)
+ this.setResponseHandler(uuid, command, resolve, reject)
+ } catch (error) {
+ this.deleteResponseHandler(uuid)
+ reject(error)
+ } finally {
+ clearTimeout(sendTimeout)
+ }