"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.globalScheduler = exports.MAX_TIMER_MILLIS = exports.ClockSym = exports.Clock = void 0;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/service/Tag"));

var _Function = /*#__PURE__*/require("@tsplus/stdlib/data/Function");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

const ClockSym = /*#__PURE__*/Symbol.for("@effect/core/io/Clock");
exports.ClockSym = ClockSym;
const Clock = {
  $: {},
  Scheduler: {},
  Tag: /*#__PURE__*/tsplus_module_1.Tag()
};
/**
 * @tsplus static ets/Clock/Ops MAX_TIMER_MILLIS
 */

exports.Clock = Clock;
const MAX_TIMER_MILLIS_1 = 2 ** 31 - 1;
const MAX_TIMER_MILLIS = MAX_TIMER_MILLIS_1;
/**
 * @tsplus static ets/Clock/Scheduler/Ops globalScheduler
 */

exports.MAX_TIMER_MILLIS = MAX_TIMER_MILLIS;
const globalScheduler = {
  unsafeSchedule(task, duration) {
    // If the duration is greater than the value allowable by the JS timer
    // functions, treat the value as an infinite duration
    if (duration.millis > MAX_TIMER_MILLIS_1) {
      return _Function.constFalse;
    }

    let completed = false;
    const handle = setTimeout(() => {
      completed = true;
      task();
    }, duration.millis);
    return () => {
      clearTimeout(handle);
      return !completed;
    };
  }

};
exports.globalScheduler = globalScheduler;
//# sourceMappingURL=definition.js.map