race(kEndEvent, kTraceEventCategory, type, asyncId);

      // Cleanup asyncId to type map
      typeMemory.delete(asyncId);
    },
  });

  return {
    enable() {
      if (this[kEnabled])
        return;
      this[kEnabled] = true;
      hook.enable();
    },

    disable() {
      if (!this[kEnabled])
        return;
      this[kEnabled] = false;
      hook.disable();
      typeMemory.clear();
    },
  };
}

exports.createHook = createHook;
