async function createTimeout()

in src/yaral.ts [308:332]


    async function createTimeout<T>(call: () => Promise<T>, req: Request): Promise<T> {
      const startTime = Date.now();
      const p = call();
      if (!options.timeout.enabled) {
        return p;
      }
      try {
        return await new Promise<T>((resolve, reject) => {
          const t = setTimeout(
            () => reject(new TimeoutError('Call Timed Out')),
            options.timeout.timeout,
          );
          p.then(innerV => {
            clearTimeout(t);
            resolve(innerV);
          }, reject);
        });
      } catch (e) {
        server.log(
          ['ratelimit', 'timeout'],
          getRequestLogDetails(e, req, true, Date.now() - startTime),
        );
        throw e;
      }
    }