Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Nov 29, 2024
1 parent 3f0b2c4 commit 643a52e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/adapter/z-stack/adapter/zStackAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ class ZStackAdapter extends Adapter {
disableRecovery: boolean,
sourceEndpoint?: number,
): Promise<Events.ZclPayload | void> {
logger.debug(`== sendZclFrameToEndpoint add to queue - ${ieeeAddr}/${networkAddress}`, NS);
return await this.queue.execute<Events.ZclPayload | void>(async () => {
this.checkInterpanLock();
return await this.sendZclFrameToEndpointInternal(
Expand Down
7 changes: 7 additions & 0 deletions src/utils/queue.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import {logger} from './logger';

interface Job {
key?: string | number;
running: boolean;
start?: () => void;
}

const NS = 'zh:queue';

class Queue {
private jobs: Job[];
private readonly concurrent: number;
Expand All @@ -14,6 +18,7 @@ class Queue {
}

public async execute<T>(func: () => Promise<T>, key?: string | number): Promise<T> {
logger.debug(`== queue add - ${key} (keys=${this.jobs.map((j) => j.key)})`, NS);
const job: Job = {key, running: false};
this.jobs.push(job);

Expand All @@ -33,9 +38,11 @@ class Queue {
}

try {
logger.debug(`== queue execute func - ${key} (keys=${this.jobs.map((j) => j.key)})`, NS);
return await func();
} finally {
this.jobs.splice(this.jobs.indexOf(job), 1);
logger.debug(`== queue remove - ${key} (keys=${this.jobs.map((j) => j.key)})`, NS);
this.executeNext();
}
}
Expand Down

0 comments on commit 643a52e

Please sign in to comment.