const queueMap = new Map>(); export function queue(key: string, func: () => Promise): Promise { 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; } }