Created
November 30, 2010 15:31
-
-
Save m1m0r1/721833 to your computer and use it in GitHub Desktop.
a hack in jsdeferred and some tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>jsDeferred</title> | |
<script type="text/javascript" src="/js/lib/jsdeferred.js"></script> | |
<script type="text/javascript"> | |
/* | |
Some tests of deferred using jsdeferred ver 0.3.4. (http://github.com/cho45/jsdeferred) | |
To see the results, try below on your browser console. | |
>>> a1(b1) | |
a1 begin | |
b1 begin | |
b1 end | |
a1 end | |
b1 later | |
>>> a2(b2) | |
a2 begin | |
b2 begin | |
b2 end | |
b2 later | |
a2 end | |
>>> a3(b3) | |
a3 begin | |
b3 begin | |
b3 later | |
a3 end | |
(b3 end) // when modified | |
A little hack on jsdeferred, from line 188: | |
_post: function(okng, fun){ | |
var next = this._next; | |
this._next = new Deferred(); | |
this._next.callback[okng] = fun; | |
this._next._next = next; | |
return this._next; | |
}, | |
*/ | |
function later(fn){ | |
setTimeout(fn, 100); | |
} | |
function a1(fn){ | |
console.log("a1", "begin"); | |
fn(); | |
console.log("a1", "end"); | |
} | |
function b1(){ | |
console.log("b1", "begin"); | |
later(function(){ | |
console.log("b1", "later"); | |
}); | |
console.log("b1", "end"); | |
} | |
function a2(fn){ | |
console.log("a2", "begin"); | |
fn().next(function(){ | |
console.log("a2", "end"); | |
}); | |
} | |
function b2(){ | |
var d = new Deferred; | |
console.log("b2", "begin"); | |
later(function(){ | |
console.log("b2", "later"); | |
d.call(); | |
}); | |
console.log("b2", "end"); | |
return d; | |
} | |
function a3(fn){ | |
console.log("a3", "begin"); | |
fn().next(function(){ | |
console.log("a3", "end"); | |
}); | |
} | |
function b3(){ | |
var d = new Deferred; | |
console.log("b3", "begin"); | |
later(function(){ | |
console.log("b3", "later"); | |
d.call(); | |
}); | |
d.next(function(){ | |
console.log("b3", "end"); | |
}); | |
return d; | |
} | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment