// A cache that expires.
module.exports = class Cache extends Map {
  constructor(timeout = 1000) {
    super();
    this.timeout = timeout;
  }
  set(key, value) {
    super.set(key, {
      tid: setTimeout(this.delete.bind(this, key), this.timeout),
      value,
    });
  }
  get(key) {
    let entry = super.get(key);
    if (entry) {
      return entry.value;
    }
    return null;
  }
  async getOrSet(key, fn) {
    if (this.has(key)) {
      return this.get(key);
    } else {
      let value = await fn();
      this.set(key, value);
      return value;
    }
  }
  delete(key) {
    let entry = super.get(key);
    if (entry) {
      clearTimeout(entry.tid);
      super.delete(key);
    }
  }
  clear() {
    for (let entry of this.values()) {
      clearTimeout(entry.tid);
    }
    super.clear();
  }
};

@@ -154,24 +154,95 @@
 y, value) %7B%0A
+    if (this.has(key)) %7B%0A      clearTimeout(super.get(key).tid);%0A    %7D%0A
     super.se
@@ -462,14 +462,8 @@
 %7D%0A  
-async 
 getO
@@ -565,14 +565,8 @@
 ue =
- await
  fn(

fix race condition with cache causing ytdl-core to hang