Skip to content

Commit

Permalink
fix: connect / disconnect events
Browse files Browse the repository at this point in the history
* * *

This commit was sponsored by Neighbourhoodie

You can hire Neighbourhoodie for all your
Hoodie / CouchDB / Offline First needs
http://go.hood.ie/thehoodiefirm
  • Loading branch information
gr2m committed Jan 16, 2016
1 parent c766317 commit 16e2e4a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -4,8 +4,8 @@ var EventEmitter = require('events').EventEmitter

var check = require('./lib/check')
var startChecking = require('./lib/start-checking')
var stopChecking = require('./lib/start-checking')
var isChecking = require('./lib/start-checking')
var stopChecking = require('./lib/stop-checking')
var isChecking = require('./lib/is-checking')
var getOk = require('./lib/get-ok')
var on = require('./lib/on')
var off = require('./lib/off')
Expand Down
8 changes: 6 additions & 2 deletions lib/check.js
Expand Up @@ -27,7 +27,9 @@ function check (state) {
state.timestamp = new Date().toISOString()

if (state.error) {
state.emitter.emit('reconnect')
process.nextTick(function () {
state.emitter.emit('reconnect')
})
delete state.error
}

Expand All @@ -37,7 +39,9 @@ function check (state) {

function handleError (state, error) {
if (!state.error) {
state.emitter.emit('disconnect')
process.nextTick(function () {
state.emitter.emit('disconnect')
})
}
state.error = error
internals.cache.set(state, error)
Expand Down
3 changes: 1 addition & 2 deletions lib/start-checking.js
Expand Up @@ -16,8 +16,7 @@ function handleInterval (state, options) {
state.interval = setTimeout(function () {
var checkAgain = handleInterval.bind(null, state, options)
internals.check(state, options).then(checkAgain, checkAgain)
}, options.interval, state, options)
return
}, options.interval)
}
}

Expand Down

0 comments on commit 16e2e4a

Please sign in to comment.