Skip to content

Commit 26e5994

Browse files
committed
feat(commands-queue): Add method to wait for in-flight commands to complete
- Introduced `waitForInflightCommandsToComplete` method to asynchronously wait for all in-flight commands to finish processing. - Utilized the `empty` event from `#waitingForReply` to signal when all commands have been completed.
1 parent ac67640 commit 26e5994

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/client/lib/client/commands-queue.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ export default class RedisCommandsQueue {
140140
this.#pushHandlers.push(handler);
141141
}
142142

143+
async waitForInflightCommandsToComplete(): Promise<void> {
144+
// In-flight commands already completed
145+
if(this.#waitingForReply.length === 0) {
146+
return
147+
};
148+
// Otherwise wait for in-flight commands to fire `empty` event
149+
return new Promise(resolve => {
150+
this.#waitingForReply.events.on('empty', resolve)
151+
});
143152
}
144153

145154
addCommand<T>(

0 commit comments

Comments
 (0)