added browser example

This commit is contained in:
AJ ONeal 2014-01-22 13:17:04 -07:00
parent 155d2c416c
commit 527d76dbd9
3 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,21 @@
window.addEventListener('load', function () {
'use strict';
function log() {
document.querySelector('#foreach-console').innerHTML +=
'\n' + Array.prototype.join.call(arguments, ' | ');
console.log.apply(console, arguments);
}
log('i', 'item', 'ms');
[2, 11, 37, 42].forEach(function (item, i) {
var ms = Math.floor(Math.random() * 1000)
;
setTimeout(function () {
log(i, item, ms);
}, ms);
});
log('All Done');
});

View File

@ -0,0 +1,25 @@
window.addEventListener('load', function () {
'use strict';
function log() {
document.querySelector('#foreachasync-console').innerHTML +=
'\n' + Array.prototype.join.call(arguments, ' | ');
console.log.apply(console, arguments);
}
var forEachAsync = window.forEachAsync
;
log('i', 'item', 'ms');
forEachAsync([2, 11, 37, 42], function (next, item, i) {
var ms = Math.floor(Math.random() * 1000)
;
setTimeout(function () {
log(i, item, ms);
next();
}, ms);
}).then(function () {
log('All Done');
});
});

View File

@ -0,0 +1,14 @@
doctype html
html
head
title forEachAsync example
script(src="bower_components/forEachAsync/forEachAsync.js")
script(src="foreach-settimeout.js")
script(src="foreachasync-settimeout.js")
body
h1 Array.prototype.forEach
code
pre#foreach-console
h1 forEachAsync
code
pre#foreachasync-console