2008-06-09 19:30:11 -07:00
|
|
|
Cu.import("resource://weave/util.js");
|
|
|
|
Cu.import("resource://weave/async.js");
|
|
|
|
|
2008-06-06 21:40:30 -07:00
|
|
|
function run_test() {
|
2008-06-16 16:42:32 -07:00
|
|
|
var fts = new FakeTimerService();
|
2008-06-06 21:40:30 -07:00
|
|
|
|
2008-06-09 19:30:11 -07:00
|
|
|
Function.prototype.async = Async.sugar;
|
2008-06-06 21:40:30 -07:00
|
|
|
|
|
|
|
var onCompleteCalled = false;
|
|
|
|
|
|
|
|
function onComplete() {
|
|
|
|
onCompleteCalled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let timesYielded = 0;
|
|
|
|
|
2008-06-07 00:34:33 -07:00
|
|
|
function testAsyncFunc(x) {
|
2008-06-06 21:40:30 -07:00
|
|
|
let self = yield;
|
|
|
|
timesYielded++;
|
|
|
|
|
2008-06-07 00:34:33 -07:00
|
|
|
// Ensure that argument was passed in properly.
|
|
|
|
do_check_eq(x, 5);
|
|
|
|
|
|
|
|
// Ensure that 'this' is set properly.
|
|
|
|
do_check_eq(this.sampleProperty, true);
|
|
|
|
|
2008-06-16 16:42:32 -07:00
|
|
|
fts.makeTimerForCall(self.cb);
|
2008-06-06 21:40:30 -07:00
|
|
|
yield;
|
|
|
|
|
|
|
|
timesYielded++;
|
2008-06-07 00:22:57 -07:00
|
|
|
self.done();
|
2008-06-06 21:40:30 -07:00
|
|
|
}
|
|
|
|
|
2008-06-07 00:34:33 -07:00
|
|
|
var thisArg = {sampleProperty: true};
|
|
|
|
testAsyncFunc.async(thisArg, onComplete, 5);
|
2008-06-06 21:40:30 -07:00
|
|
|
|
|
|
|
do_check_eq(timesYielded, 1);
|
|
|
|
|
2008-06-16 16:42:32 -07:00
|
|
|
do_check_true(fts.processCallback());
|
2008-06-06 21:40:30 -07:00
|
|
|
|
|
|
|
do_check_eq(timesYielded, 2);
|
|
|
|
|
2008-06-20 13:58:56 -07:00
|
|
|
do_check_eq(Async.outstandingGenerators.length, 1);
|
|
|
|
|
2008-06-16 16:42:32 -07:00
|
|
|
do_check_true(fts.processCallback());
|
2008-06-06 21:40:30 -07:00
|
|
|
|
2008-06-16 16:42:32 -07:00
|
|
|
do_check_false(fts.processCallback());
|
2008-06-18 16:11:15 -07:00
|
|
|
|
2008-06-20 13:58:56 -07:00
|
|
|
do_check_eq(Async.outstandingGenerators.length, 0);
|
2008-06-06 21:40:30 -07:00
|
|
|
}
|