doh.Deferredを使用して、次の一連のイベントをチェックするテストを作成しようとしています。
- ユーザー A でログイン (非同期)
- ログアウト (同期)
- ユーザー A でログイン (非同期)
2 番目のコールバック関数の戻り値は、別の doh.Deferred オブジェクトです。d のコールバック チェーンは d2 を待機するという印象を受けましたが、そうではありません。テストは d2.callback が呼び出される前に終了します。
ここでどこが間違っていますか?
この動作をテストするためのより良い方法を知っている人はいますか?
function test() {
var d = new doh.Deferred();
d.addCallback(function() {
Comm.logout(); /* synchronus */
try {
// check with doh.t and doh.is
return true;
} catch (e) {
d.errback(e);
}
});
d.addCallback(function() {
var d2 = new dojo.Deferred();
/* asynchronus - third parameter is a callback */
Comm.login('alex', 'asdf', function(result, msg) {
try {
// check with doh.t and doh.is
d2.callback(true);
} catch (e) {
d2.errback(e);
}
});
return d2; // returning doh.Defferred -- expect d to wait for d2.callback
});
/* asynchronus - third parameter is a callback */
Comm.login('larry', '123', function (result, msg) {
try {
// check with doh.t and doh.is
d.callback(true);
} catch (e) {
d.errback(e);
}
});
return d;
}