Pot.Deferred.prototype.cancel

{Pot.Deferred} Pot.Deferred.prototype.cancel ()

Pot.js と PotLite.js で利用可能。

Deferred チェインを中止します。

Deferred チェインを中止します。
中止すると、次以降のチェインは実行されません。

var d = new Pot.Deferred();

d.then(function() {
    debug(1);
}).then(function() {
    debug(2);
});

// チェックが通れば開始
if (check()) {
    d.begin();
} else {
    // 通らなければ中止
    d.cancel();
    // キャンセルしたチェインに追加しても何も起きない
    d.then(function() {
        debug('hoge');
    });
    d.begin(); // begin も無視される
}

コールバックチェインの中で cancel する場合。

Pot.Deferred.begin(function() {
    debug(1);
}).then(function() {
    debug(2);
    // ここでキャンセル
    this.cancel();
}).then(function() {
    // このコールバック関数は実行されない
    debug(3);
});

チェイン上で実行される コールバック関数内の this は、 自身の Pot.Deferred インスタンスです。