@fedify/fedify
Version:
An ActivityPub server framework
48 lines (45 loc) • 1.19 kB
JavaScript
import { Temporal } from "@js-temporal/polyfill";
import { URLPattern } from "urlpattern-polyfill";
globalThis.addEventListener = () => {};
//#region x/denokv.ts
/**
* Represents a message queue adapter that uses Deno KV store.
*/
var DenoKvMessageQueue = class {
#kv;
/**
* Deno KV queues provide automatic retry with exponential backoff.
* @since 1.7.0
*/
nativeRetrial = true;
/**
* Constructs a new {@link DenoKvMessageQueue} adapter with the given Deno KV
* store.
* @param kv The Deno KV store to use.
*/
constructor(kv) {
this.#kv = kv;
}
async enqueue(message, options) {
await this.#kv.enqueue(message, options?.delay == null ? void 0 : { delay: Math.max(options.delay.total("millisecond"), 0) });
}
listen(handler, options = {}) {
options.signal?.addEventListener("abort", () => {
try {
this.#kv.close();
} catch (e) {
if (!(e instanceof Deno.errors.BadResource)) throw e;
}
}, { once: true });
return this.#kv.listenQueue(handler);
}
[Symbol.dispose]() {
try {
this.#kv.close();
} catch (e) {
if (!(e instanceof Deno.errors.BadResource)) throw e;
}
}
};
//#endregion
export { DenoKvMessageQueue };