Lab - callLater waterfall
by heenan
HTML
<h1>This is here for debugging.</h1>
<p>Open up your browser console to interact directly with the Promsies.</p>
JavaScript
/**
* Write a function
* callLater(fn, ms);
* that expects two arguments, a function and time in milliseconds
*
* The function will set up the passed fn to be invoked after ms milliseconds
* It should return a promise that is fulfilled once fn function runs
* It should reject if the ms delay is 0 or less.
* (tip: uses promises and setTimeout)
*
* Bonus:
* Write another function:
* callLaterWaterfall(fns, ms);
* The function expects two arguments, an array of functions and time in ms
* Upon invokation it will run each function in sequence, with
* ms milliseconds delay between calls
* (tip: uses promises, async and await)
*/
function callLater(fn, ms) {
var prom = new Promise(function(fullfill, reject) {
setTimeout(function() {
fn();
fullfill(1);
}, ms);
});
}
callLater(function() {
console.log('i did it');
}, 1000);
// test me here...
// callLater();