0

I have a grunt task that kicks off a socket-io server among other things.

I have found a way of keeping the task 'open' (ie, not exiting straight away on the command line) by running the 'watch' task right after it. e.g

grunt.registerTask('default', ["mytask", "watch"]);

But this requires me to fill in some dummy data in the Gruntfile such as.

// Not needed...
watch: {
  files: "test/*"
},

So is there a way to keep my task running without having to use the watch task along with it?

Thanks

shane
  • 852
  • 1
  • 8
  • 16

2 Answers2

0

This functionality is built into grunt

grunt.registerTask('asyncme', 'My asynchronous task.', function() {
   var done = this.async();
   doSomethingAsync(done);
});
shane
  • 852
  • 1
  • 8
  • 16
0

Here is an example from http://gruntjs.com/creating-tasks

Tasks can be asynchronous.

grunt.registerTask('asyncfoo', 'My "asyncfoo" task.', function() {
    // Force task into async mode and grab a handle to the "done" function.
    var done = this.async();
    // Run some sync stuff.
    grunt.log.writeln('Processing task...');
    // And some async stuff.
    setTimeout(function() {
        grunt.log.writeln('All done!');
        done();
    }, 1000);
});
udidu
  • 8,269
  • 6
  • 48
  • 68