Created
November 13, 2013 15:06
-
-
Save garth/7450560 to your computer and use it in GitHub Desktop.
Grunt task to wait for a port to become open
This file contains hidden or 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
'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