@fedify/redis 2.2.0-pr.715.28 → 2.2.0-pr.731.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mq.cjs CHANGED
@@ -7,6 +7,25 @@ const logger = (0, require("@logtape/logtape").getLogger)([
7
7
  "redis",
8
8
  "mq"
9
9
  ]);
10
+ function isRedisClosedError(error) {
11
+ return error instanceof Error && /connection is (already )?closed/i.test(error.message);
12
+ }
13
+ async function quitRedisGracefully(redis) {
14
+ const client = redis;
15
+ if (client.status === "wait" || client.status === "end") {
16
+ client.disconnect();
17
+ return;
18
+ }
19
+ if (typeof client.quit !== "function") {
20
+ client.disconnect();
21
+ return;
22
+ }
23
+ try {
24
+ await client.quit();
25
+ } catch (error) {
26
+ if (!isRedisClosedError(error)) throw error;
27
+ }
28
+ }
10
29
  /**
11
30
  * A message queue that uses Redis as the underlying storage.
12
31
  *
@@ -200,9 +219,15 @@ var RedisMessageQueue = class {
200
219
  }
201
220
  [Symbol.dispose]() {
202
221
  clearInterval(this.#loopHandle);
222
+ this.#loopHandle = void 0;
203
223
  this.#redis.disconnect();
204
224
  this.#subRedis.disconnect();
205
225
  }
226
+ async [Symbol.asyncDispose]() {
227
+ clearInterval(this.#loopHandle);
228
+ this.#loopHandle = void 0;
229
+ await Promise.all([quitRedisGracefully(this.#redis), quitRedisGracefully(this.#subRedis)]);
230
+ }
206
231
  };
207
232
  //#endregion
208
233
  exports.RedisMessageQueue = RedisMessageQueue;
package/dist/mq.d.cts CHANGED
@@ -81,6 +81,7 @@ declare class RedisMessageQueue implements MessageQueue, Disposable {
81
81
  enqueueMany(messages: readonly any[], options?: MessageQueueEnqueueOptions): Promise<void>;
82
82
  listen(handler: (message: any) => void | Promise<void>, options?: MessageQueueListenOptions): Promise<void>;
83
83
  [Symbol.dispose](): void;
84
+ [Symbol.asyncDispose](): Promise<void>;
84
85
  }
85
86
  //#endregion
86
87
  export { RedisMessageQueue, RedisMessageQueueOptions };
package/dist/mq.d.ts CHANGED
@@ -82,6 +82,7 @@ declare class RedisMessageQueue implements MessageQueue, Disposable {
82
82
  enqueueMany(messages: readonly any[], options?: MessageQueueEnqueueOptions): Promise<void>;
83
83
  listen(handler: (message: any) => void | Promise<void>, options?: MessageQueueListenOptions): Promise<void>;
84
84
  [Symbol.dispose](): void;
85
+ [Symbol.asyncDispose](): Promise<void>;
85
86
  }
86
87
  //#endregion
87
88
  export { RedisMessageQueue, RedisMessageQueueOptions };
package/dist/mq.js CHANGED
@@ -7,6 +7,25 @@ const logger = getLogger([
7
7
  "redis",
8
8
  "mq"
9
9
  ]);
10
+ function isRedisClosedError(error) {
11
+ return error instanceof Error && /connection is (already )?closed/i.test(error.message);
12
+ }
13
+ async function quitRedisGracefully(redis) {
14
+ const client = redis;
15
+ if (client.status === "wait" || client.status === "end") {
16
+ client.disconnect();
17
+ return;
18
+ }
19
+ if (typeof client.quit !== "function") {
20
+ client.disconnect();
21
+ return;
22
+ }
23
+ try {
24
+ await client.quit();
25
+ } catch (error) {
26
+ if (!isRedisClosedError(error)) throw error;
27
+ }
28
+ }
10
29
  /**
11
30
  * A message queue that uses Redis as the underlying storage.
12
31
  *
@@ -200,9 +219,15 @@ var RedisMessageQueue = class {
200
219
  }
201
220
  [Symbol.dispose]() {
202
221
  clearInterval(this.#loopHandle);
222
+ this.#loopHandle = void 0;
203
223
  this.#redis.disconnect();
204
224
  this.#subRedis.disconnect();
205
225
  }
226
+ async [Symbol.asyncDispose]() {
227
+ clearInterval(this.#loopHandle);
228
+ this.#loopHandle = void 0;
229
+ await Promise.all([quitRedisGracefully(this.#redis), quitRedisGracefully(this.#subRedis)]);
230
+ }
206
231
  };
207
232
  //#endregion
208
233
  export { RedisMessageQueue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/redis",
3
- "version": "2.2.0-pr.715.28+06979f5f",
3
+ "version": "2.2.0-pr.731.0.33+a54d18e7",
4
4
  "description": "Redis drivers for Fedify",
5
5
  "keywords": [
6
6
  "fedify",
@@ -82,7 +82,7 @@
82
82
  },
83
83
  "peerDependencies": {
84
84
  "ioredis": "^5.8.2",
85
- "@fedify/fedify": "^2.2.0-pr.715.28+06979f5f"
85
+ "@fedify/fedify": "^2.2.0-pr.731.0.33+a54d18e7"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@std/async": "npm:@jsr/std__async@^1.0.13",
@@ -90,7 +90,7 @@
90
90
  "tsdown": "^0.21.6",
91
91
  "typescript": "^5.9.2",
92
92
  "@fedify/fixture": "^2.0.0",
93
- "@fedify/testing": "^2.2.0-pr.715.28+06979f5f"
93
+ "@fedify/testing": "^2.2.0-pr.731.0.33+a54d18e7"
94
94
  },
95
95
  "scripts": {
96
96
  "build:self": "tsdown",