Skip to content

Instantly share code, notes, and snippets.

@richardj
Created October 31, 2014 09:10
Show Gist options
  • Save richardj/ce020fe077f95c690c91 to your computer and use it in GitHub Desktop.
Save richardj/ce020fe077f95c690c91 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
html {
font-family: sans-serif;
}
</style>
</head>
<body>
<script id="jsbin-javascript">
function wait(ms) {
return new Promise(function(r) {
setTimeout(r, ms);
});
}
function randomWait() {
return wait(Math.random() * 5000);
}
function fetchHello() {
return randomWait().then(function() {
return "Hello";
});
}
function fetchWorld() {
return randomWait().then(function() {
return "World";
});
}
function fetchFoobar() {
return randomWait().then(function() {
return "Foobar";
});
}
[fetchHello(), fetchWorld(), fetchFoobar()].reduce(function(chain, promise) {
return chain.then(function() {
return promise;
}).then(function(value) {
document.body.appendChild(
document.createTextNode(value + ' ')
);
});
}, Promise.resolve());
</script>
<script id="jsbin-source-css" type="text/css">html {
font-family: sans-serif;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">function wait(ms) {
return new Promise(function(r) {
setTimeout(r, ms);
});
}
function randomWait() {
return wait(Math.random() * 5000);
}
function fetchHello() {
return randomWait().then(function() {
return "Hello";
});
}
function fetchWorld() {
return randomWait().then(function() {
return "World";
});
}
function fetchFoobar() {
return randomWait().then(function() {
return "Foobar";
});
}
[fetchHello(), fetchWorld(), fetchFoobar()].reduce(function(chain, promise) {
return chain.then(function() {
return promise;
}).then(function(value) {
document.body.appendChild(
document.createTextNode(value + ' ')
);
});
}, Promise.resolve());</script></body>
</html>
html {
font-family: sans-serif;
}
function wait(ms) {
return new Promise(function(r) {
setTimeout(r, ms);
});
}
function randomWait() {
return wait(Math.random() * 5000);
}
function fetchHello() {
return randomWait().then(function() {
return "Hello";
});
}
function fetchWorld() {
return randomWait().then(function() {
return "World";
});
}
function fetchFoobar() {
return randomWait().then(function() {
return "Foobar";
});
}
[fetchHello(), fetchWorld(), fetchFoobar()].reduce(function(chain, promise) {
return chain.then(function() {
return promise;
}).then(function(value) {
document.body.appendChild(
document.createTextNode(value + ' ')
);
});
}, Promise.resolve());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment