Newer
Older
vue-indexer / node_modules / puppeteer-core / src / common / TimeoutSettings.ts
@eugene-sukhodolskiy eugene-sukhodolskiy on 24 Sep 931 bytes v1.0
/**
 * @license
 * Copyright 2019 Google Inc.
 * SPDX-License-Identifier: Apache-2.0
 */

const DEFAULT_TIMEOUT = 30000;

/**
 * @internal
 */
export class TimeoutSettings {
  #defaultTimeout: number | null;
  #defaultNavigationTimeout: number | null;

  constructor() {
    this.#defaultTimeout = null;
    this.#defaultNavigationTimeout = null;
  }

  setDefaultTimeout(timeout: number): void {
    this.#defaultTimeout = timeout;
  }

  setDefaultNavigationTimeout(timeout: number): void {
    this.#defaultNavigationTimeout = timeout;
  }

  navigationTimeout(): number {
    if (this.#defaultNavigationTimeout !== null) {
      return this.#defaultNavigationTimeout;
    }
    if (this.#defaultTimeout !== null) {
      return this.#defaultTimeout;
    }
    return DEFAULT_TIMEOUT;
  }

  timeout(): number {
    if (this.#defaultTimeout !== null) {
      return this.#defaultTimeout;
    }
    return DEFAULT_TIMEOUT;
  }
}