Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function main() {
- var d = accessAndShowEntries();
- d.addCallback(function() {
- console.log("finish");
- });
- setTimeout(function() {
- console.log("cancel!");
- d.cancel();
- }, 2500);
- }
- function accessAndShowEntries() {
- function loop(i) {
- if (i >= 5) return;
- return accessEntry(i).addCallback(function (data) {
- console.log(data);
- return callLater(0, loop, i + 1);
- });
- }
- return callLater(0, loop, 0);
- }
- // XHR で何かアクセスする代わり
- function accessEntry(i) {
- var d = new Deferred();
- var cb = d.callback.bind(d, "foo"+i);
- var timerId = setTimeout(cb, 1000);
- d.canceller = function () {
- clearTimeout(timerId);
- };
- return d;
- }
Add Comment
Please, Sign In to add comment