diff options
author | crupest <crupest@outlook.com> | 2020-08-05 23:29:14 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-08-05 23:29:14 +0800 |
commit | 2f39aae59e150e93748a60d6f8202d5c6790b3b7 (patch) | |
tree | 0d57e19dc215673d362d437d124b4bcad5bb08c6 /Timeline/ClientApp/src/app/data/queue.ts | |
parent | 6177e4fc237aedf62b7d6011f19f04d98c26da39 (diff) | |
download | timeline-2f39aae59e150e93748a60d6f8202d5c6790b3b7.tar.gz timeline-2f39aae59e150e93748a60d6f8202d5c6790b3b7.tar.bz2 timeline-2f39aae59e150e93748a60d6f8202d5c6790b3b7.zip |
Refactor a lot.
Diffstat (limited to 'Timeline/ClientApp/src/app/data/queue.ts')
-rw-r--r-- | Timeline/ClientApp/src/app/data/queue.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Timeline/ClientApp/src/app/data/queue.ts b/Timeline/ClientApp/src/app/data/queue.ts new file mode 100644 index 00000000..001340a9 --- /dev/null +++ b/Timeline/ClientApp/src/app/data/queue.ts @@ -0,0 +1,14 @@ +const queueMap = new Map<string, Promise<null>>();
+
+export function queue<T>(key: string, func: () => Promise<T>): Promise<T> {
+ const last = queueMap.get(key);
+ if (last == null) {
+ const promise = func();
+ queueMap.set(key, promise.then(null, null));
+ return promise;
+ } else {
+ const promise = last.then(() => func());
+ queueMap.set(key, promise.then(null, null));
+ return promise;
+ }
+}
|