Created
September 26, 2013 16:02
-
-
Save ben-bradley/6716283 to your computer and use it in GitHub Desktop.
Simple function to simulate async
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
/********************************************/ | |
/* insert random delays to simulate latency */ | |
/********************************************/ | |
function delay(callback, n) { | |
var r = Math.floor(Math.random()*(n || 5000)); | |
setTimeout(function() { callback(); }, r); | |
} | |
// specify a max on the delay timer range | |
delay(function() { console.log('BLARGH!'); }, 10000); | |
// use default 5000ms max timer | |
delay(sayHonk); | |
function sayHonk() { console.log('HONK!'); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment