Created
February 2, 2015 15:18
-
-
Save hax/634bd6240ac011d3244c to your computer and use it in GitHub Desktop.
// source http://jsbin.com/raxeve
This file contains hidden or 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> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// See https://github.com/promises-aplus/promises-spec/issues/179 | |
'use strict' | |
var logs = [] | |
function log(s) { | |
return function () { | |
logs.push(s) | |
} | |
} | |
setTimeout(function () { console.log(logs.join(' ')) }, 100) | |
var r1, r2 | |
var a = new Promise(function (resolve) { r1 = resolve }) | |
var b = new Promise(function (resolve) { r2 = resolve }) | |
var f0, r0 | |
var p0 = new Promise(function (onFulfilled, onRejected) { | |
f0 = onFulfilled | |
r0 = onRejected | |
}) | |
var t0 = p0.then | |
p0.then = function () { | |
log('then')() | |
t0.apply(this, arguments) | |
} | |
a.then(log('a1')) | |
b.then(log('b1')) | |
b.then(log('b2')) | |
a.then(log('a2')) | |
r1(p0) | |
r2(p0) | |
a.then(log('a3')) | |
b.then(log('b3')) | |
b.then(log('b4')) | |
a.then(log('a4')) | |
f0() | |
a.then(log('a5')) | |
b.then(log('b5')) | |
b.then(log('b6')) | |
a.then(log('a6')) | |
setTimeout(function () { | |
log('timeout')() | |
a.then(log('a7')) | |
b.then(log('b7')) | |
b.then(log('b8')) | |
a.then(log('a8')) | |
}) | |
log('async')() | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// See https://github.com/promises-aplus/promises-spec/issues/179 | |
'use strict' | |
var logs = [] | |
function log(s) { | |
return function () { | |
logs.push(s) | |
} | |
} | |
setTimeout(function () { console.log(logs.join(' ')) }, 100) | |
var r1, r2 | |
var a = new Promise(function (resolve) { r1 = resolve }) | |
var b = new Promise(function (resolve) { r2 = resolve }) | |
var f0, r0 | |
var p0 = new Promise(function (onFulfilled, onRejected) { | |
f0 = onFulfilled | |
r0 = onRejected | |
}) | |
var t0 = p0.then | |
p0.then = function () { | |
log('then')() | |
t0.apply(this, arguments) | |
} | |
a.then(log('a1')) | |
b.then(log('b1')) | |
b.then(log('b2')) | |
a.then(log('a2')) | |
r1(p0) | |
r2(p0) | |
a.then(log('a3')) | |
b.then(log('b3')) | |
b.then(log('b4')) | |
a.then(log('a4')) | |
f0() | |
a.then(log('a5')) | |
b.then(log('b5')) | |
b.then(log('b6')) | |
a.then(log('a6')) | |
setTimeout(function () { | |
log('timeout')() | |
a.then(log('a7')) | |
b.then(log('b7')) | |
b.then(log('b8')) | |
a.then(log('a8')) | |
}) | |
log('async')() | |
</script></body> | |
</html> |
This file contains hidden or 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
// See https://github.com/promises-aplus/promises-spec/issues/179 | |
'use strict' | |
var logs = [] | |
function log(s) { | |
return function () { | |
logs.push(s) | |
} | |
} | |
setTimeout(function () { console.log(logs.join(' ')) }, 100) | |
var r1, r2 | |
var a = new Promise(function (resolve) { r1 = resolve }) | |
var b = new Promise(function (resolve) { r2 = resolve }) | |
var f0, r0 | |
var p0 = new Promise(function (onFulfilled, onRejected) { | |
f0 = onFulfilled | |
r0 = onRejected | |
}) | |
var t0 = p0.then | |
p0.then = function () { | |
log('then')() | |
t0.apply(this, arguments) | |
} | |
a.then(log('a1')) | |
b.then(log('b1')) | |
b.then(log('b2')) | |
a.then(log('a2')) | |
r1(p0) | |
r2(p0) | |
a.then(log('a3')) | |
b.then(log('b3')) | |
b.then(log('b4')) | |
a.then(log('a4')) | |
f0() | |
a.then(log('a5')) | |
b.then(log('b5')) | |
b.then(log('b6')) | |
a.then(log('a6')) | |
setTimeout(function () { | |
log('timeout')() | |
a.then(log('a7')) | |
b.then(log('b7')) | |
b.then(log('b8')) | |
a.then(log('a8')) | |
}) | |
log('async')() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment