Skip to content

Instantly share code, notes, and snippets.

@matthewstokeley
Last active August 21, 2019 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewstokeley/c06a36c68c718250ebfc to your computer and use it in GitHub Desktop.
Save matthewstokeley/c06a36c68c718250ebfc to your computer and use it in GitHub Desktop.
callback methods for grunt.task.run
// module pattern in case i add a callback / task queue list
var task = function (tasks) {
return {
run: function() {
// run task
grunt.task.run(tasks);
},
on: function(val, callback) {
// run task
this.run();
// counter
var i = 0;
// set interval
var checkExist = setInterval(function() {
// check grunt.config for value - easily change to grunt.option
if(grunt.config(val)) {
// stop setInterval
clearInterval(checkExist)
// call the callback
callback.call();
} else {
// throw a warning after 500ms, edit for longer tasks
if (i == 100) {
clearInterval(checkExist);
grunt.fail.warn(grunt.util.error("The value doesn't exist or the task has timed out"));
}
}
i++;
}, 50);
}
}
}
// implmentation
task('prompt:grid').on('options.layout.grid', function() {
console.log('a')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment