Skip to content

Commit 160a0c6

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 f20d903 commit 160a0c6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ export default class RedisCommandsQueue {
138138
this.#pushHandlers.push(handler);
139139
}
140140

141+
async waitForInflightCommandsToComplete(): Promise<void> {
142+
// In-flight commands already completed
143+
if(this.#waitingForReply.length === 0) {
144+
return
145+
};
146+
// Otherwise wait for in-flight commands to fire `empty` event
147+
return new Promise(resolve => {
148+
this.#waitingForReply.events.on('empty', resolve)
149+
});
150+
}
151+
141152
addCommand<T>(
142153
args: ReadonlyArray<RedisArgument>,
143154
options?: CommandOptions

0 commit comments

Comments
 (0)