33import assert from "node:assert" ;
44import { EventEmitter } from "node:events" ;
55import net from "node:net" ;
6-
76import { DelimiterParser } from "@serialport/parser-delimiter" ;
8-
9- import { Queue } from "../../../utils" ;
7+ import { AsyncMutex } from "../../../utils/async-mutex" ;
108import { logger } from "../../../utils/logger" ;
119import { Waitress } from "../../../utils/waitress" ;
1210import * as ZSpec from "../../../zspec" ;
@@ -79,7 +77,7 @@ export default class ZiGate extends EventEmitter<ZiGateEventMap> {
7977 private parser ?: EventEmitter ;
8078 private serialPort ?: SerialPort ;
8179 private socketPort ?: net . Socket ;
82- private queue : Queue ;
80+ private queue : AsyncMutex ;
8381
8482 public portWrite ?: SerialPort | net . Socket ;
8583 private waitress : Waitress < ZiGateObject , WaitressMatcher > ;
@@ -92,7 +90,7 @@ export default class ZiGate extends EventEmitter<ZiGateEventMap> {
9290 // XXX: not used?
9391 // this.rtscts = typeof serialPortOptions.rtscts === 'boolean' ? serialPortOptions.rtscts : false;
9492 this . initialized = false ;
95- this . queue = new Queue ( 1 ) ;
93+ this . queue = new AsyncMutex ( ) ;
9694
9795 this . waitress = new Waitress < ZiGateObject , WaitressMatcher > ( this . waitressValidator , this . waitressTimeoutFormatter ) ;
9896 this . zdoWaitress = new Waitress < ZdoWaitressPayload , ZdoWaitressMatcher > ( this . zdoWaitressValidator , this . waitressTimeoutFormatter ) ;
@@ -107,7 +105,7 @@ export default class ZiGate extends EventEmitter<ZiGateEventMap> {
107105 ) : Promise < ZiGateObject > {
108106 const waiters : Promise < ZiGateObject > [ ] = [ ] ;
109107 const waitersId : number [ ] = [ ] ;
110- return await this . queue . execute ( async ( ) => {
108+ return await this . queue . run ( async ( ) => {
111109 try {
112110 logger . debug (
113111 ( ) => `Send command \x1b[32m>>>> ${ ZiGateCommandCode [ code ] } 0x${ zeroPad ( code ) } <<<<\x1b[0m \nPayload: ${ JSON . stringify ( payload ) } ` ,
@@ -163,7 +161,7 @@ export default class ZiGate extends EventEmitter<ZiGateEventMap> {
163161 }
164162
165163 public async requestZdo ( clusterId : Zdo . ClusterId , payload : Buffer ) : Promise < boolean > {
166- return await this . queue . execute ( async ( ) => {
164+ return await this . queue . run ( async ( ) => {
167165 const commandCode = ZDO_REQ_CLUSTER_ID_TO_ZIGATE_COMMAND_ID [ clusterId ] ;
168166 assert ( commandCode !== undefined , `ZDO cluster ID '${ clusterId } ' not supported.` ) ;
169167 const ruleStatus : ZiGateResponseMatcher = [
0 commit comments