Skip to content

Instantly share code, notes, and snippets.

@ben-bradley
Created September 26, 2013 16:02
Show Gist options
  • Save ben-bradley/6716283 to your computer and use it in GitHub Desktop.
Save ben-bradley/6716283 to your computer and use it in GitHub Desktop.
Simple function to simulate async
/********************************************/
/* 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