Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[fix] #70 request for version should be performed async and aborted i…

…f jitsu finishes before the request finishes
  • Loading branch information...
commit e189205f4a3cc4f1e6219c3cd66c2bcb3ded5d61 1 parent 82cdd59
Bradley Meck bmeck authored
Showing with 24 additions and 19 deletions.
  1. +15 −1 lib/jitsu.js
  2. +9 −18 lib/jitsu/utils/index.js
16 lib/jitsu.js
View
@@ -87,7 +87,21 @@ jitsu.start = function (argv, callback) {
winston.info('Welcome to ' + 'Nodejitsu'.grey);
winston.info('It worked if it ends with ' + 'Nodejitsu'.grey + ' ok'.green.bold);
- jitsu.utils.checkVersion(function () {
+ jitsu.utils.checkVersion(function (handler) {
+ var oldCallback = callback;
+ callback = function() {
+ if(handler.req) {
+ var timer = setTimeout(function() {
+ if(handler.req) {
+ handler.req.abort();
+ }
+ handler.on('end', function() {
+ clearTimeout(timer);
+ })
+ }, 200);
+ }
+ oldCallback.call(this, arguments);
+ }
jitsu.config.load(function (err) {
if (err) {
callback(err);
27 lib/jitsu/utils/index.js
View
@@ -144,21 +144,10 @@ utils.checkVersion = function (callback) {
var responded = false
//
- // Only allow the `checkVersion` function 200ms
- // to attempt to contact GitHub.
- //
- setTimeout(function () {
- if (!responded) {
- responded = true;
- callback();
- }
- }, 200);
-
- //
// Check the GitHub tags for `jitsu` to see if the current
- // version is outdated.
+ // version is outdated. If it is not make sure to message the user at the end.
//
- request({
+ var handler = request({
uri: 'http://registry.npmjs.org/jitsu/latest'
}, function (err, res, body) {
if (!responded) {
@@ -168,8 +157,10 @@ utils.checkVersion = function (callback) {
var pkg = JSON.parse(body);
if (semver.gt(pkg.version, jitsu.version)) {
- winston.warn('A newer version of jitsu is available: ' + pkg.version);
- winston.warn('Please run `npm update jitsu`');
+ process.on('exit', function() {
+ winston.warn('A newer version of jitsu is available: ' + pkg.version);
+ winston.warn('Please run `npm update jitsu`');
+ });
}
}
catch (ex) {
@@ -178,8 +169,8 @@ utils.checkVersion = function (callback) {
// of an upgrade at the next possible opportunity.
//
}
-
- callback();
}
});
-};
+
+ callback(handler);
+};
Please sign in to comment.
Something went wrong with that request. Please try again.