mirror of
https://github.com/ION606/archivebot.git
synced 2026-06-06 07:52:57 +00:00
Started adding slash commands, doesn't work though
This commit is contained in:
+148
@@ -0,0 +1,148 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
# [@sapphire/async-queue@1.5.0](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.4.0...@sapphire/async-queue@1.5.0) - (2022-08-16)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- **deps:** Update all non-major dependencies ([2308bd7](https://github.com/sapphiredev/utilities/commit/2308bd74356b6b2e0c12995b25f4d8ade4803fe9))
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- Add `AsyncQueue#abortAll` (#429) ([b351e70](https://github.com/sapphiredev/utilities/commit/b351e70ebef329009daaebba89729ee84bb5704c))
|
||||
|
||||
# [@sapphire/async-queue@1.4.0](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.3.1...@sapphire/async-queue@1.4.0) - (2022-08-07)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
|
||||
- **deps:** Update all non-major dependencies ([84af0db](https://github.com/sapphiredev/utilities/commit/84af0db2db749223b036aa99fe19a2e9af5681c6))
|
||||
- **deps:** Update all non-major dependencies ([50cd8de](https://github.com/sapphiredev/utilities/commit/50cd8dea593b6f5ae75571209456b3421e2ca59a))
|
||||
|
||||
## 📝 Documentation
|
||||
|
||||
- Add @muchnameless as a contributor ([a1221fe](https://github.com/sapphiredev/utilities/commit/a1221fea68506e99591d5d00ec552a07c26833f9))
|
||||
- Add @enxg as a contributor ([d2382f0](https://github.com/sapphiredev/utilities/commit/d2382f04e3909cb4ad11798a0a10e683f6cf5383))
|
||||
- Add @EvolutionX-10 as a contributor ([efc3a32](https://github.com/sapphiredev/utilities/commit/efc3a320a72ae258996dd62866d206c33f8d4961))
|
||||
- Add @MajesticString as a contributor ([295b3e9](https://github.com/sapphiredev/utilities/commit/295b3e9849a4b0fe64074bae02f6426378a303c3))
|
||||
- Add @Mzato0001 as a contributor ([c790ef2](https://github.com/sapphiredev/utilities/commit/c790ef25df2d7e22888fa9f8169167aa555e9e19))
|
||||
- Add @NotKaskus as a contributor ([00da8f1](https://github.com/sapphiredev/utilities/commit/00da8f199137b9277119823f322d1f2d168d928a))
|
||||
- Add @imranbarbhuiya as a contributor ([fb674c2](https://github.com/sapphiredev/utilities/commit/fb674c2c5594d41e71662263553dcb4bac9e37f4))
|
||||
- Add @axisiscool as a contributor ([ce1aa31](https://github.com/sapphiredev/utilities/commit/ce1aa316871a88d3663efbdf2a42d3d8dfe6a27f))
|
||||
- Add @dhruv-kaushikk as a contributor ([ebbf43f](https://github.com/sapphiredev/utilities/commit/ebbf43f63617daba96e72c50a234bf8b64f6ddc4))
|
||||
- Add @Commandtechno as a contributor ([f1d69fa](https://github.com/sapphiredev/utilities/commit/f1d69fabe1ee0abe4be08b19e63dbec03102f7ce))
|
||||
- Fix typedoc causing OOM crashes ([63ba41c](https://github.com/sapphiredev/utilities/commit/63ba41c4b6678554b1c7043a22d3296db4f59360))
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
- **AsyncQueue:** Add AbortSignal support (#417) ([c0629e7](https://github.com/sapphiredev/utilities/commit/c0629e781ebc3f48e496a0851191b32e91f62fe9))
|
||||
|
||||
## 🧪 Testing
|
||||
|
||||
- Migrate to vitest (#380) ([075ec73](https://github.com/sapphiredev/utilities/commit/075ec73c7a8e3374fad3ada612d37eb4ac36ec8d))
|
||||
|
||||
## [1.3.1](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.3.0...@sapphire/async-queue@1.3.1) (2022-04-01)
|
||||
|
||||
**Note:** Version bump only for package @sapphire/async-queue
|
||||
|
||||
# [1.3.0](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.2.0...@sapphire/async-queue@1.3.0) (2022-03-06)
|
||||
|
||||
### Features
|
||||
|
||||
- allow module: NodeNext ([#306](https://github.com/sapphiredev/utilities/issues/306)) ([9dc6dd6](https://github.com/sapphiredev/utilities/commit/9dc6dd619efab879bb2b0b3c9e64304e10a67ed6))
|
||||
- **ts-config:** add multi-config structure ([#281](https://github.com/sapphiredev/utilities/issues/281)) ([b5191d7](https://github.com/sapphiredev/utilities/commit/b5191d7f2416dc5838590c4ff221454925553e37))
|
||||
|
||||
# [1.2.0](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.9...@sapphire/async-queue@1.2.0) (2022-01-28)
|
||||
|
||||
### Features
|
||||
|
||||
- change build system to tsup ([#270](https://github.com/sapphiredev/utilities/issues/270)) ([365a53a](https://github.com/sapphiredev/utilities/commit/365a53a5517a01a0926cf28a83c96b63f32ed9f8))
|
||||
|
||||
## [1.1.9](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.8...@sapphire/async-queue@1.1.9) (2021-11-06)
|
||||
|
||||
**Note:** Version bump only for package @sapphire/async-queue
|
||||
|
||||
## [1.1.8](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.7...@sapphire/async-queue@1.1.8) (2021-10-26)
|
||||
|
||||
**Note:** Version bump only for package @sapphire/async-queue
|
||||
|
||||
## [1.1.7](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.6...@sapphire/async-queue@1.1.7) (2021-10-17)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- allow more node & npm versions in engines field ([5977d2a](https://github.com/sapphiredev/utilities/commit/5977d2a30a4b2cfdf84aff3f33af03ffde1bbec5))
|
||||
|
||||
## [1.1.6](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.5...@sapphire/async-queue@1.1.6) (2021-10-11)
|
||||
|
||||
**Note:** Version bump only for package @sapphire/async-queue
|
||||
|
||||
## [1.1.5](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.4...@sapphire/async-queue@1.1.5) (2021-10-04)
|
||||
|
||||
**Note:** Version bump only for package @sapphire/async-queue
|
||||
|
||||
## [1.1.4](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.3...@sapphire/async-queue@1.1.4) (2021-06-27)
|
||||
|
||||
**Note:** Version bump only for package @sapphire/async-queue
|
||||
|
||||
## [1.1.3](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.2...@sapphire/async-queue@1.1.3) (2021-06-06)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- remove peer deps, update dev deps, update READMEs ([#124](https://github.com/sapphiredev/utilities/issues/124)) ([67256ed](https://github.com/sapphiredev/utilities/commit/67256ed43b915b02a8b5c68230ba82d6210c5032))
|
||||
|
||||
## [1.1.2](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.1...@sapphire/async-queue@1.1.2) (2021-05-20)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **async-queue:** mark package as side effect free ([1c4b901](https://github.com/sapphiredev/utilities/commit/1c4b901cda3d14bd085c35cc74e160f844567ba7))
|
||||
|
||||
## [1.1.1](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.1.0...@sapphire/async-queue@1.1.1) (2021-05-02)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- drop the `www.` from the SapphireJS URL ([494d89f](https://github.com/sapphiredev/utilities/commit/494d89ffa04f78c195b93d7905b3232884f7d7e2))
|
||||
- update all the SapphireJS URLs from `.com` to `.dev` ([f59b46d](https://github.com/sapphiredev/utilities/commit/f59b46d1a0ebd39cad17b17d71cd3b9da808d5fd))
|
||||
|
||||
# [1.1.0](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.7...@sapphire/async-queue@1.1.0) (2021-04-21)
|
||||
|
||||
### Features
|
||||
|
||||
- add @sapphire/embed-jsx ([#100](https://github.com/sapphiredev/utilities/issues/100)) ([7277a23](https://github.com/sapphiredev/utilities/commit/7277a236015236ed8e81b7882875410facc4ce17))
|
||||
|
||||
## [1.0.7](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.6...@sapphire/async-queue@1.0.7) (2021-04-19)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- change all Sapphire URLs from "project"->"community" & use our domain where applicable 👨🌾🚜 ([#102](https://github.com/sapphiredev/utilities/issues/102)) ([835b408](https://github.com/sapphiredev/utilities/commit/835b408e8e57130c3787aca2e32613346ff23e4d))
|
||||
|
||||
## [1.0.6](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.5...@sapphire/async-queue@1.0.6) (2021-04-03)
|
||||
|
||||
**Note:** Version bump only for package @sapphire/async-queue
|
||||
|
||||
## [1.0.5](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.4...@sapphire/async-queue@1.0.5) (2021-03-16)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- remove terser from all packages ([#79](https://github.com/sapphiredev/utilities/issues/79)) ([1cfe4e7](https://github.com/sapphiredev/utilities/commit/1cfe4e7c804e62c142495686d2b83b81d0026c02))
|
||||
|
||||
## [1.0.4](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.3...@sapphire/async-queue@1.0.4) (2021-02-16)
|
||||
|
||||
**Note:** Version bump only for package @sapphire/async-queue
|
||||
|
||||
## [1.0.3](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.2...@sapphire/async-queue@1.0.3) (2021-02-13)
|
||||
|
||||
**Note:** Version bump only for package @sapphire/async-queue
|
||||
|
||||
## [1.0.2](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.1...@sapphire/async-queue@1.0.2) (2021-01-25)
|
||||
|
||||
**Note:** Version bump only for package @sapphire/async-queue
|
||||
|
||||
## [1.0.1](https://github.com/sapphiredev/utilities/compare/@sapphire/async-queue@1.0.0...@sapphire/async-queue@1.0.1) (2021-01-16)
|
||||
|
||||
**Note:** Version bump only for package @sapphire/async-queue
|
||||
|
||||
# 1.0.0 (2021-01-13)
|
||||
|
||||
### Features
|
||||
|
||||
- **async-queue:** add async-queue package ([#56](https://github.com/sapphiredev/utilities/issues/56)) ([ba81832](https://github.com/sapphiredev/utilities/commit/ba8183287dbbc3f3d7d79af6d5a2d3dd8d62f63e))
|
||||
+12
@@ -93,6 +93,18 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://c43721.dev/"><img src="https://avatars.githubusercontent.com/u/55610086?v=4?s=100" width="100px;" alt=""/><br /><sub><b>c43721</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=c43721" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://commandtechno.com/"><img src="https://avatars.githubusercontent.com/u/68407783?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Commandtechno</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Commandtechno" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/dhruv-kaushikk"><img src="https://avatars.githubusercontent.com/u/73697546?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=dhruv-kaushikk" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://axis.moe/"><img src="https://avatars.githubusercontent.com/u/54381371?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=axisiscool" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/imranbarbhuiya"><img src="https://avatars.githubusercontent.com/u/74945038?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Parbez</b></sub></a><br /><a href="#maintenance-imranbarbhuiya" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://github.com/NotKaskus"><img src="https://avatars.githubusercontent.com/u/75168528?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Paul Andrew</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=NotKaskus" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://linktr.ee/mzato0001"><img src="https://avatars.githubusercontent.com/u/62367547?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mzato</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Mzato0001" title="Code">💻</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AMzato0001" title="Bug reports">🐛</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/MajesticString"><img src="https://avatars.githubusercontent.com/u/66224939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harry Allen</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=MajesticString" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/EvolutionX-10"><img src="https://avatars.githubusercontent.com/u/85353424?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Evo</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=EvolutionX-10" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://enes.ovh/"><img src="https://avatars.githubusercontent.com/u/61084101?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Enes Genç</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=enxg" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/muchnameless"><img src="https://avatars.githubusercontent.com/u/12682826?v=4?s=100" width="100px;" alt=""/><br /><sub><b>muchnameless</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=muchnameless" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
+55
-2
@@ -1,2 +1,55 @@
|
||||
export * from './lib/AsyncQueue';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
/**
|
||||
* The AsyncQueue class used to sequentialize burst requests
|
||||
*/
|
||||
declare class AsyncQueue {
|
||||
/**
|
||||
* The amount of entries in the queue, including the head.
|
||||
* @seealso {@link queued} for the queued count.
|
||||
*/
|
||||
get remaining(): number;
|
||||
/**
|
||||
* The amount of queued entries.
|
||||
* @seealso {@link remaining} for the count with the head.
|
||||
*/
|
||||
get queued(): number;
|
||||
/**
|
||||
* The promises array
|
||||
*/
|
||||
private promises;
|
||||
/**
|
||||
* Waits for last promise and queues a new one
|
||||
* @example
|
||||
* ```typescript
|
||||
* const queue = new AsyncQueue();
|
||||
* async function request(url, options) {
|
||||
* await queue.wait({ signal: options.signal });
|
||||
* try {
|
||||
* const result = await fetch(url, options);
|
||||
* // Do some operations with 'result'
|
||||
* } finally {
|
||||
* // Remove first entry from the queue and resolve for the next entry
|
||||
* queue.shift();
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* request(someUrl1, someOptions1); // Will call fetch() immediately
|
||||
* request(someUrl2, someOptions2); // Will call fetch() after the first finished
|
||||
* request(someUrl3, someOptions3); // Will call fetch() after the second finished
|
||||
* ```
|
||||
*/
|
||||
wait(options?: Readonly<AsyncQueueWaitOptions>): Promise<void>;
|
||||
/**
|
||||
* Unlocks the head lock and transfers the next lock (if any) to the head.
|
||||
*/
|
||||
shift(): void;
|
||||
/**
|
||||
* Aborts all the pending promises.
|
||||
* @note To avoid race conditions, this does **not** unlock the head lock.
|
||||
*/
|
||||
abortAll(): void;
|
||||
}
|
||||
interface AsyncQueueWaitOptions {
|
||||
signal?: AbortSignal | undefined | null;
|
||||
}
|
||||
|
||||
export { AsyncQueue, AsyncQueueWaitOptions };
|
||||
|
||||
+85
-26
@@ -1,28 +1,24 @@
|
||||
"use strict";
|
||||
var SapphireAsyncQueue = (() => {
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __reExport = (target, module, copyDefault, desc) => {
|
||||
if (module && typeof module === "object" || typeof module === "function") {
|
||||
for (let key of __getOwnPropNames(module))
|
||||
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
||||
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return target;
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
||||
return (module, temp) => {
|
||||
return cache && cache.get(module) || (temp = __reExport(__markAsModule({}), module, 1), cache && cache.set(module, temp), temp);
|
||||
};
|
||||
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var __publicField = (obj, key, value) => {
|
||||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
return value;
|
||||
@@ -34,6 +30,54 @@ var SapphireAsyncQueue = (() => {
|
||||
AsyncQueue: () => AsyncQueue
|
||||
});
|
||||
|
||||
// src/lib/AsyncQueueEntry.ts
|
||||
var AsyncQueueEntry = class {
|
||||
constructor(queue) {
|
||||
__publicField(this, "promise");
|
||||
__publicField(this, "resolve");
|
||||
__publicField(this, "reject");
|
||||
__publicField(this, "queue");
|
||||
__publicField(this, "signal", null);
|
||||
__publicField(this, "signalListener", null);
|
||||
this.queue = queue;
|
||||
this.promise = new Promise((resolve, reject) => {
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
});
|
||||
}
|
||||
setSignal(signal) {
|
||||
if (signal.aborted)
|
||||
return this;
|
||||
this.signal = signal;
|
||||
this.signalListener = () => {
|
||||
const index = this.queue["promises"].indexOf(this);
|
||||
if (index !== -1)
|
||||
this.queue["promises"].splice(index, 1);
|
||||
this.reject(new Error("Request aborted manually"));
|
||||
};
|
||||
this.signal.addEventListener("abort", this.signalListener);
|
||||
return this;
|
||||
}
|
||||
use() {
|
||||
this.dispose();
|
||||
this.resolve();
|
||||
return this;
|
||||
}
|
||||
abort() {
|
||||
this.dispose();
|
||||
this.reject(new Error("Request aborted manually"));
|
||||
return this;
|
||||
}
|
||||
dispose() {
|
||||
if (this.signal) {
|
||||
this.signal.removeEventListener("abort", this.signalListener);
|
||||
this.signal = null;
|
||||
this.signalListener = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
__name(AsyncQueueEntry, "AsyncQueueEntry");
|
||||
|
||||
// src/lib/AsyncQueue.ts
|
||||
var AsyncQueue = class {
|
||||
constructor() {
|
||||
@@ -42,22 +86,37 @@ var SapphireAsyncQueue = (() => {
|
||||
get remaining() {
|
||||
return this.promises.length;
|
||||
}
|
||||
wait() {
|
||||
const next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();
|
||||
let resolve;
|
||||
const promise = new Promise((res) => {
|
||||
resolve = res;
|
||||
});
|
||||
this.promises.push({
|
||||
resolve,
|
||||
promise
|
||||
});
|
||||
return next;
|
||||
get queued() {
|
||||
return this.remaining === 0 ? 0 : this.remaining - 1;
|
||||
}
|
||||
wait(options) {
|
||||
const entry = new AsyncQueueEntry(this);
|
||||
if (this.promises.length === 0) {
|
||||
this.promises.push(entry);
|
||||
return Promise.resolve();
|
||||
}
|
||||
this.promises.push(entry);
|
||||
if (options?.signal)
|
||||
entry.setSignal(options.signal);
|
||||
return entry.promise;
|
||||
}
|
||||
shift() {
|
||||
const deferred = this.promises.shift();
|
||||
if (typeof deferred !== "undefined")
|
||||
deferred.resolve();
|
||||
if (this.promises.length === 0)
|
||||
return;
|
||||
if (this.promises.length === 1) {
|
||||
this.promises.shift();
|
||||
return;
|
||||
}
|
||||
this.promises.shift();
|
||||
this.promises[0].use();
|
||||
}
|
||||
abortAll() {
|
||||
if (this.queued === 0)
|
||||
return;
|
||||
for (let i = 1; i < this.promises.length; ++i) {
|
||||
this.promises[i].abort();
|
||||
}
|
||||
this.promises.length = 1;
|
||||
}
|
||||
};
|
||||
__name(AsyncQueue, "AsyncQueue");
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+86
-27
@@ -1,28 +1,24 @@
|
||||
"use strict";
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __reExport = (target, module2, copyDefault, desc) => {
|
||||
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
||||
for (let key of __getOwnPropNames(module2))
|
||||
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
||||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return target;
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
||||
return (module2, temp) => {
|
||||
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
||||
};
|
||||
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var __publicField = (obj, key, value) => {
|
||||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
return value;
|
||||
@@ -33,6 +29,55 @@ var src_exports = {};
|
||||
__export(src_exports, {
|
||||
AsyncQueue: () => AsyncQueue
|
||||
});
|
||||
module.exports = __toCommonJS(src_exports);
|
||||
|
||||
// src/lib/AsyncQueueEntry.ts
|
||||
var AsyncQueueEntry = class {
|
||||
constructor(queue) {
|
||||
__publicField(this, "promise");
|
||||
__publicField(this, "resolve");
|
||||
__publicField(this, "reject");
|
||||
__publicField(this, "queue");
|
||||
__publicField(this, "signal", null);
|
||||
__publicField(this, "signalListener", null);
|
||||
this.queue = queue;
|
||||
this.promise = new Promise((resolve, reject) => {
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
});
|
||||
}
|
||||
setSignal(signal) {
|
||||
if (signal.aborted)
|
||||
return this;
|
||||
this.signal = signal;
|
||||
this.signalListener = () => {
|
||||
const index = this.queue["promises"].indexOf(this);
|
||||
if (index !== -1)
|
||||
this.queue["promises"].splice(index, 1);
|
||||
this.reject(new Error("Request aborted manually"));
|
||||
};
|
||||
this.signal.addEventListener("abort", this.signalListener);
|
||||
return this;
|
||||
}
|
||||
use() {
|
||||
this.dispose();
|
||||
this.resolve();
|
||||
return this;
|
||||
}
|
||||
abort() {
|
||||
this.dispose();
|
||||
this.reject(new Error("Request aborted manually"));
|
||||
return this;
|
||||
}
|
||||
dispose() {
|
||||
if (this.signal) {
|
||||
this.signal.removeEventListener("abort", this.signalListener);
|
||||
this.signal = null;
|
||||
this.signalListener = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
__name(AsyncQueueEntry, "AsyncQueueEntry");
|
||||
|
||||
// src/lib/AsyncQueue.ts
|
||||
var AsyncQueue = class {
|
||||
@@ -42,26 +87,40 @@ var AsyncQueue = class {
|
||||
get remaining() {
|
||||
return this.promises.length;
|
||||
}
|
||||
wait() {
|
||||
const next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();
|
||||
let resolve;
|
||||
const promise = new Promise((res) => {
|
||||
resolve = res;
|
||||
});
|
||||
this.promises.push({
|
||||
resolve,
|
||||
promise
|
||||
});
|
||||
return next;
|
||||
get queued() {
|
||||
return this.remaining === 0 ? 0 : this.remaining - 1;
|
||||
}
|
||||
wait(options) {
|
||||
const entry = new AsyncQueueEntry(this);
|
||||
if (this.promises.length === 0) {
|
||||
this.promises.push(entry);
|
||||
return Promise.resolve();
|
||||
}
|
||||
this.promises.push(entry);
|
||||
if (options?.signal)
|
||||
entry.setSignal(options.signal);
|
||||
return entry.promise;
|
||||
}
|
||||
shift() {
|
||||
const deferred = this.promises.shift();
|
||||
if (typeof deferred !== "undefined")
|
||||
deferred.resolve();
|
||||
if (this.promises.length === 0)
|
||||
return;
|
||||
if (this.promises.length === 1) {
|
||||
this.promises.shift();
|
||||
return;
|
||||
}
|
||||
this.promises.shift();
|
||||
this.promises[0].use();
|
||||
}
|
||||
abortAll() {
|
||||
if (this.queued === 0)
|
||||
return;
|
||||
for (let i = 1; i < this.promises.length; ++i) {
|
||||
this.promises[i].abort();
|
||||
}
|
||||
this.promises.length = 1;
|
||||
}
|
||||
};
|
||||
__name(AsyncQueue, "AsyncQueue");
|
||||
module.exports = __toCommonJS(src_exports);
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
AsyncQueue
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+77
-14
@@ -6,6 +6,54 @@ var __publicField = (obj, key, value) => {
|
||||
return value;
|
||||
};
|
||||
|
||||
// src/lib/AsyncQueueEntry.ts
|
||||
var AsyncQueueEntry = class {
|
||||
constructor(queue) {
|
||||
__publicField(this, "promise");
|
||||
__publicField(this, "resolve");
|
||||
__publicField(this, "reject");
|
||||
__publicField(this, "queue");
|
||||
__publicField(this, "signal", null);
|
||||
__publicField(this, "signalListener", null);
|
||||
this.queue = queue;
|
||||
this.promise = new Promise((resolve, reject) => {
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
});
|
||||
}
|
||||
setSignal(signal) {
|
||||
if (signal.aborted)
|
||||
return this;
|
||||
this.signal = signal;
|
||||
this.signalListener = () => {
|
||||
const index = this.queue["promises"].indexOf(this);
|
||||
if (index !== -1)
|
||||
this.queue["promises"].splice(index, 1);
|
||||
this.reject(new Error("Request aborted manually"));
|
||||
};
|
||||
this.signal.addEventListener("abort", this.signalListener);
|
||||
return this;
|
||||
}
|
||||
use() {
|
||||
this.dispose();
|
||||
this.resolve();
|
||||
return this;
|
||||
}
|
||||
abort() {
|
||||
this.dispose();
|
||||
this.reject(new Error("Request aborted manually"));
|
||||
return this;
|
||||
}
|
||||
dispose() {
|
||||
if (this.signal) {
|
||||
this.signal.removeEventListener("abort", this.signalListener);
|
||||
this.signal = null;
|
||||
this.signalListener = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
__name(AsyncQueueEntry, "AsyncQueueEntry");
|
||||
|
||||
// src/lib/AsyncQueue.ts
|
||||
var AsyncQueue = class {
|
||||
constructor() {
|
||||
@@ -14,22 +62,37 @@ var AsyncQueue = class {
|
||||
get remaining() {
|
||||
return this.promises.length;
|
||||
}
|
||||
wait() {
|
||||
const next = this.promises.length ? this.promises[this.promises.length - 1].promise : Promise.resolve();
|
||||
let resolve;
|
||||
const promise = new Promise((res) => {
|
||||
resolve = res;
|
||||
});
|
||||
this.promises.push({
|
||||
resolve,
|
||||
promise
|
||||
});
|
||||
return next;
|
||||
get queued() {
|
||||
return this.remaining === 0 ? 0 : this.remaining - 1;
|
||||
}
|
||||
wait(options) {
|
||||
const entry = new AsyncQueueEntry(this);
|
||||
if (this.promises.length === 0) {
|
||||
this.promises.push(entry);
|
||||
return Promise.resolve();
|
||||
}
|
||||
this.promises.push(entry);
|
||||
if (options?.signal)
|
||||
entry.setSignal(options.signal);
|
||||
return entry.promise;
|
||||
}
|
||||
shift() {
|
||||
const deferred = this.promises.shift();
|
||||
if (typeof deferred !== "undefined")
|
||||
deferred.resolve();
|
||||
if (this.promises.length === 0)
|
||||
return;
|
||||
if (this.promises.length === 1) {
|
||||
this.promises.shift();
|
||||
return;
|
||||
}
|
||||
this.promises.shift();
|
||||
this.promises[0].use();
|
||||
}
|
||||
abortAll() {
|
||||
if (this.queued === 0)
|
||||
return;
|
||||
for (let i = 1; i < this.promises.length; ++i) {
|
||||
this.promises[i].abort();
|
||||
}
|
||||
this.promises.length = 1;
|
||||
}
|
||||
};
|
||||
__name(AsyncQueue, "AsyncQueue");
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
-40
@@ -1,40 +0,0 @@
|
||||
/**
|
||||
* The AsyncQueue class used to sequentialize burst requests
|
||||
*/
|
||||
export declare class AsyncQueue {
|
||||
/**
|
||||
* The remaining amount of queued promises
|
||||
*/
|
||||
get remaining(): number;
|
||||
/**
|
||||
* The promises array
|
||||
*/
|
||||
private promises;
|
||||
/**
|
||||
* Waits for last promise and queues a new one
|
||||
* @example
|
||||
* ```typescript
|
||||
* const queue = new AsyncQueue();
|
||||
* async function request(url, options) {
|
||||
* await queue.wait();
|
||||
* try {
|
||||
* const result = await fetch(url, options);
|
||||
* // Do some operations with 'result'
|
||||
* } finally {
|
||||
* // Remove first entry from the queue and resolve for the next entry
|
||||
* queue.shift();
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* request(someUrl1, someOptions1); // Will call fetch() immediately
|
||||
* request(someUrl2, someOptions2); // Will call fetch() after the first finished
|
||||
* request(someUrl3, someOptions3); // Will call fetch() after the second finished
|
||||
* ```
|
||||
*/
|
||||
wait(): Promise<void>;
|
||||
/**
|
||||
* Frees the queue's lock for the next item to process
|
||||
*/
|
||||
shift(): void;
|
||||
}
|
||||
//# sourceMappingURL=AsyncQueue.d.ts.map
|
||||
+64
-54
@@ -1,55 +1,65 @@
|
||||
{
|
||||
"name": "@sapphire/async-queue",
|
||||
"version": "1.3.0",
|
||||
"description": "Sequential asynchronous lock-based queue for promises",
|
||||
"author": "@sapphire",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.mjs",
|
||||
"browser": "dist/index.global.js",
|
||||
"unpkg": "dist/index.global.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"typedocMain": "src/index.ts",
|
||||
"exports": {
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/async-queue",
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
|
||||
"build": "tsup && tsc -b src",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sapphiredev/utilities.git",
|
||||
"directory": "packages/async-queue"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"!dist/*.tsbuildinfo"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=v14.0.0",
|
||||
"npm": ">=7.0.0"
|
||||
},
|
||||
"keywords": [
|
||||
"@sapphire/async-queue",
|
||||
"bot",
|
||||
"typescript",
|
||||
"ts",
|
||||
"yarn",
|
||||
"discord",
|
||||
"sapphire",
|
||||
"standalone"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/sapphiredev/utilities/issues"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
"name": "@sapphire/async-queue",
|
||||
"version": "1.5.0",
|
||||
"description": "Sequential asynchronous lock-based queue for promises",
|
||||
"author": "@sapphire",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.mjs",
|
||||
"browser": "dist/index.global.js",
|
||||
"unpkg": "dist/index.global.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"exports": {
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/async-queue",
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
|
||||
"build": "tsup",
|
||||
"prepack": "yarn build",
|
||||
"bump": "cliff-jumper",
|
||||
"check-update": "cliff-jumper --dry-run"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sapphiredev/utilities.git",
|
||||
"directory": "packages/async-queue"
|
||||
},
|
||||
"files": [
|
||||
"dist/**/*.js*",
|
||||
"dist/**/*.mjs*",
|
||||
"dist/**/*.d*"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=v14.0.0",
|
||||
"npm": ">=7.0.0"
|
||||
},
|
||||
"keywords": [
|
||||
"@sapphire/async-queue",
|
||||
"bot",
|
||||
"typescript",
|
||||
"ts",
|
||||
"yarn",
|
||||
"discord",
|
||||
"sapphire",
|
||||
"standalone"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/sapphiredev/utilities/issues"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@favware/cliff-jumper": "^1.8.6",
|
||||
"@vitest/coverage-c8": "^0.22.0",
|
||||
"c8": "^7.12.0",
|
||||
"tsup": "^6.2.2",
|
||||
"typescript": "^4.7.4",
|
||||
"vitest": "^0.22.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user