# All files / src Relude_Timer.bs.js

85.19% Statements 23/27
100% Branches 2/2
75% Functions 6/8
85.19% Lines 23/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48

    2x
    2x
    2x

    1x
    1x

    1x
    1x

    1x
    1x
    1x
    1x
    1x

    1x
    1x
    3x
    3x
    3x
    1x

    2x

    1x

    2x
    2x
    2x

     'use strict';

    var Curry = require("bs-platform/lib/js/curry.js");
    var Caml_option = require("bs-platform/lib/js/caml_option.js");
    var Relude_Option = require("./Relude_Option.bs.js");

    function delay(delayMS, f) {
      var timerId = setTimeout(f, delayMS);
      return (function (param) {
          clearTimeout(timerId);
          return /* () */0;
        });
    }

    function repeat(delayMS, f) {
      var timerId = setInterval(f, delayMS);
      return (function (param) {
          clearInterval(timerId);
          return /* () */0;
        });
    }

    function repeatTimes(delayMS, times, f) {
      var timerId = /* record */[/* contents */undefined];
      var cancel = function (param) {
        return Curry._2(Relude_Option.forEach, (function (prim) {
                      clearInterval(prim);
                      return /* () */0;
                    }), timerId[0]);
      };
      var callCount = /* record */[/* contents */0];
      timerId[0] = Caml_option.some(setInterval((function (param) {
                  Curry._1(f, /* () */0);
                  callCount[0] = callCount[0] + 1 | 0;
                  if (callCount[0] === times) {
                    return cancel(/* () */0);
                  } else {
                    return 0;
                  }
                }), delayMS));
      return cancel;
    }

    exports.delay = delay;
    exports.repeat = repeat;
    exports.repeatTimes = repeatTimes;
    /* Relude_Option Not a pure module */