Skip to content

Instantly share code, notes, and snippets.

@garth
Created November 13, 2013 15:06
Show Gist options
  • Save garth/7450560 to your computer and use it in GitHub Desktop.
Save garth/7450560 to your computer and use it in GitHub Desktop.
Grunt task to wait for a port to become open
'use strict';
var portscanner = require('portscanner');
var port = 3001;
module.exports = function (grunt) {
grunt.registerTask('waitForPort', 'Waits until a port is open', function() {
grunt.log.write('Waiting to the development server to come online...');
var done = this.async();
var timer = setInterval(function () {
portscanner.checkPortStatus(port, 'localhost', function (error, status) {
if (status === 'open') {
clearInterval(timer);
grunt.log.writeln('ready.');
done();
}
else {
grunt.log.write('.');
}
});
}, 50);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment