Skip to content

Instantly share code, notes, and snippets.

@ruzz311
Created January 14, 2015 19:27
Show Gist options
  • Save ruzz311/a0da00404d15fb4ddd77 to your computer and use it in GitHub Desktop.
Save ruzz311/a0da00404d15fb4ddd77 to your computer and use it in GitHub Desktop.
A grunt task to wait for a given amount of time
"use strict";
function formatDuration(duration) {
var resultType = 'ms';
var resultVal = duration;
if (duration > 999 && duration < 60000) {
resultType = 'sec';
resultVal = duration / 1000;
} else if (duration > 59999 && duration < 3600000) {
resultType = 'min';
resultVal = (duration / 1000) / 60;
} else if (duration > 3599999) {
resultType = 'hr';
resultVal = ((duration / 1000) / 60) / 60;
}
return {
type: resultType,
val: resultVal
};
}
module.exports = function (grunt) {
grunt.registerTask("wait_for", function (waitDuration) {
var done = this.async();
var rand = Math.floor(Math.random() * (10000 - 1 + 1)) + 1;
var formattedDur = formatDuration(waitDuration);
setTimeout(function () {
grunt.log.writeln('[wait#' + rand + '] complete!');
done();
}, waitDuration);
grunt.log.writeln('[wait#' + rand + '] waiting for ' + formattedDur.val + ' ' + formattedDur.type + '... ');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment