Skip to content

Commit

Permalink
fix(server): livereload now waits for server to finish restarting
Browse files Browse the repository at this point in the history
closes #42
  • Loading branch information
DaftMonk committed Feb 14, 2014
1 parent b37eb00 commit 71d63f0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion templates/common/Gruntfile.js
Expand Up @@ -94,7 +94,7 @@ module.exports = function (grunt) {
'server.js',
'lib/**/*.{js,json}'
],
tasks: ['newer:jshint:server', 'express:dev'],
tasks: ['newer:jshint:server', 'express:dev', 'wait'],
options: {
livereload: true,
nospawn: true //Without this option specified express won't be reloaded
Expand Down Expand Up @@ -427,6 +427,18 @@ module.exports = function (grunt) {
}
});

// Used for delaying livereload until after server has restarted
grunt.registerTask('wait', function () {
grunt.log.ok('Waiting for server reload...');

var done = this.async();

setTimeout(function () {
grunt.log.writeln('Done waiting!');
done();
}, 500);
});

grunt.registerTask('express-keepalive', 'Keep grunt running', function() {
this.async();
});
Expand Down

4 comments on commit 71d63f0

@jeef3
Copy link
Contributor

@jeef3 jeef3 commented on 71d63f0 Feb 14, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, but a shame you had to result to using a timeout 😟

@DaftMonk
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah :(, fortunately it's not very noticeable.

@jeef3
Copy link
Contributor

@jeef3 jeef3 commented on 71d63f0 Feb 14, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be more concerned about the day the server reload takes > 500ms.

@DaftMonk
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I was able to find a case where I was able to trigger the problem consistently and I couldn't get it to fail at 500ms, but other people might need to increase that for it to work consistently. I'll add a project configuration variable for it if it looks like some people still have issues.

Please sign in to comment.