0

各反復でランダムな有効期限が必要です。この例では、有効期限を5〜15秒の間でランダム化し、永久に使用します。

var timer = qx.util.TimerManager.getInstance();
timer.start(function(userData, timerId)
    {
        this.debug("timer tick");
    },
    (Math.floor(Math.random()*11)*1000) + 5000,
    this,
    null,
    0
);

純粋なJSソリューションがある場合はそれも受け入れます。

http://demo.qooxdoo.org/current/apiviewer/#qx.util.TimerManager

4

1 に答える 1

1

問題は、recurTimeTimerManager.startの引数が通常の関数の通常の引数であるため、関数が呼び出されたときに1回だけ評価されることです。何度も何度も再評価される表現ではありません。つまり、TimerManagerでは等距離の実行しか得られません。

qx.event.Timer.onceおそらく、呼び出しごとにタイムアウトを新たに計算するなど、必要なものを手動でコーディングする必要があります。

編集:

これがあなたにとって正しい方向に進むかもしれないコードスニペットです(これはqooxdooクラスのコンテキストで機能します):

var that = this;
function doStuff(timeout) {
  // do the things here you want to do in every timeout
  // this example just logs the new calculated time offset
  that.debug(timeout);
}

function callBack() {
  // this just calls doStuff and handles a new time offset
  var timeout = (Math.floor(Math.random()*11)*1000) + 5000;
  doStuff(timeout);
  qx.event.Timer.once(callBack, that, timeout);
}

// fire off the first execution
qx.event.Timer.once(callBack, that, 5000);
于 2011-05-08T08:52:01.827 に答える