Last active
August 21, 2019 07:49
-
-
Save matthewstokeley/c06a36c68c718250ebfc to your computer and use it in GitHub Desktop.
callback methods for grunt.task.run
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
// 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