2010年2月13日土曜日

QUnut + JSDeferred, テストのためにnextに手を入れる。

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
nextの中に手を突っ込んで、callbackの前後でstart/stopすることを目的に書き換えたのだが、なにかうまくいって無くて、testの結果が記録されない。
なにを見落としているのだろう?
var AJAXTIMEOUT = 100;
var surpress_stop  = false;
(function(){
  Deferred.prototype._fire = function (okng, value) {
    var next = "ok";
    start();
    debug('+++');
    try {
      value = this.callback[okng].call(this, value);
    } catch (e) {
      next  = "ng";
      value = e;
      if (Deferred.onerror) Deferred.onerror(e);
    }
    if (!surpress_stop){
      debug('---');
      stop(AJAXTIMEOUT);
    }
    if (value instanceof Deferred) {
      value._next = this._next;
    } else {
      if (this._next) this._next._fire(next, value);
    }
    return this;
  }
})();


2/16追記... startの中でsetTimeoutしているので、nextにフックするべきではない。start/stop pairはtestの中で1つだけにすべき。13msの遅延が何を引き起こすか予想不能。非同期問い合わせが返ってくる前にqueueからテストケースを抜いて実行されると不味い。
        start: function() {
                // A slight delay, to avoid any current callbacks
                if ( window.setTimeout ) {
                        window.setTimeout(function() {
                                if ( config.timeout ) {
                                        clearTimeout(config.timeout);
                                }

                                config.blocking = false;
                                process();
                        }, 13);
                } else {
                        config.blocking = false;
                        process();
                }
        },

0 件のコメント: