timerOnceBefore static method

void timerOnceBefore(
  1. Function callback,
  2. int ms
)

do nothing if the callback is already in the list and will get called after 0 ~ N ms

Implementation

static void timerOnceBefore(Function callback, int ms) {
  var desiredTime50 =
      (((DateTime.now()).millisecondsSinceEpoch + ms) / 50).ceil();
  if (_functionsMap.containsKey(callback)) {
    var existTf = _functionsMap[callback]!;
    if (existTf.ts50 <= desiredTime50) {
      return;
    } else {
      existTf.remove(callback);
    }
  }

  if (desiredTime50 <= _lastTimeRun) {
    callLater(callback);
    return;
  }
  var tf = _getTimerFunctions(desiredTime50);
  tf.add(callback);
  _functionsMap[callback] = tf;
}