IKHSAN
EN Read in EnglishID

homeio

Publik

Fork dari doctor-io/homeio

Branch
main
Commit terakhir
958d74616 Oktober 2026

async-utils.mjs

Buka raw
import { DBUS_METHOD_TIMEOUT_MS } from "./config.mjs";
import { HelperServiceError } from "./errors.mjs";

function withTimeout(promise, timeoutMs = DBUS_METHOD_TIMEOUT_MS) {
  let timeoutHandle;
  return Promise.race([
    promise.finally(() => {
      if (timeoutHandle) clearTimeout(timeoutHandle);
    }),
    new Promise((_, reject) => {
      timeoutHandle = setTimeout(() => {
        reject(
          new HelperServiceError("DBus operation timeout", {
            code: "timeout",
            statusCode: 504,
          }),
        );
      }, timeoutMs);
    }),
  ]);
}

export { withTimeout };
byte
606
baris
24
Jenis
mjs
Commit terakhir
16 Oktober 2026