function killItWhileEmitting() { function c1() { Assert.ok(true, "c1 called");
} function c2() { Assert.ok(true, "c2 called");
emitter.off("tick", c3);
} function c3() { Assert.ok(false, "c3 should not be called");
} function c4() { Assert.ok(true, "c4 called");
}
Assert.ok(!enteredC1, "c1 should not be called");
}
}
function testPromise() {
let emitter = new EventEmitter();
let p = emitter.once("thing");
// Check that the promise do_check_eq only resolved once event though we // emit("thing") more than once
let firstCallbackCalled = false;
let check1 = p.then(arg => { Assert.equal(firstCallbackCalled, false, "first callback called only once");
firstCallbackCalled = true; Assert.equal(arg, "happened", "correct arg in promise"); return"rval from c1";
});
emitter.emit("thing", "happened", "ignored");
// Check that the promise do_check_eq resolved asynchronously
let secondCallbackCalled = false;
let check2 = p.then(arg => { Assert.ok(true, "second callback called"); Assert.equal(arg, "happened", "correct arg in promise");
secondCallbackCalled = true; Assert.equal(arg, "happened", "correct arg in promise (a second time)"); return"rval from c2";
});
// Shouldn't call any of the above listeners
emitter.emit("thing", "trashinate");
// Check that we can still separate events with different names // and that it works with no parameters
let pfoo = emitter.once("foo");
let pbar = emitter.once("bar");
let check3 = pfoo.then(arg => { Assert.equal(arg, undefined, "no arg for foo event"); return"rval from c3";
});
pbar.then(() => { Assert.ok(false, "pbar should not be called");
});
emitter.emit("foo");
Assert.equal(secondCallbackCalled, false, "second callback not called yet");
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.3Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.