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 | be9eb313ccad0832cb37e1c63e03608c47c2d171 (patch) | |
tree | e989d42596f60b5b2157341edb5ec7ea648d1881 /Timeline/ClientApp/src/app/data/queue.ts | |
parent | 0791682e1f333adb5c79b979e3e8c5c50bb5f85a (diff) | |
download | timeline-be9eb313ccad0832cb37e1c63e03608c47c2d171.tar.gz timeline-be9eb313ccad0832cb37e1c63e03608c47c2d171.tar.bz2 timeline-be9eb313ccad0832cb37e1c63e03608c47c2d171.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;
+ }
+}
|