Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
Always return an error in a cb
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed May 13, 2017
1 parent b0f1afd commit b03ee10
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions bin/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ require('update-notifier')({pkg: pkg}).notify()

var Configstore = require('configstore')
var configName = 'update-notifier-' + pkg.name

var config = new Configstore(configName, {
nodeVersions: []
})
var config = new Configstore(configName, { nodeVersions: [] })

var lastFetchCheck = config.get('lastFetchCheck')
var now = Date.now()
Expand All @@ -20,16 +17,16 @@ var isCacheValid = now - lastFetchCheck < fetchCheckInterval
var nodeVersions = config.get('nodeVersions')
var hasVersions = nodeVersions.length

var fetch = require('./fetch')

function loadConfig (cb) {
if (hasVersions && isCacheValid) return cb(nodeVersions)
require('./fetch')(function (err, nodeVersions) {
if (err) {
if (hasVersions) return cb(nodeVersions)
throw err
}
if (hasVersions && isCacheValid) return cb(null, nodeVersions)

fetch(function (err, nodeVersions) {
if (err) return cb(hasVersions ? null : err, nodeVersions)
config.set('nodeVersions', nodeVersions)
config.set('lastFetchCheck', Date.now())
return cb(nodeVersions)
return cb(null, nodeVersions)
})
}

Expand Down

0 comments on commit b03ee10

Please sign in to comment.