Skip to content

Instantly share code, notes, and snippets.

@maxfi
Created February 13, 2019 06:25
Show Gist options
  • Save maxfi/90681baeffc85c31c2c5a31bf561e809 to your computer and use it in GitHub Desktop.
Save maxfi/90681baeffc85c31c2c5a31bf561e809 to your computer and use it in GitHub Desktop.
[Meteor custom reconnect] #meteor
import { Meteor } from 'meteor/meteor'
import _ from 'lodash/fp'
Meteor.startup(() => {
Tracker.autorun(() => {
const { status, retryCount } = Meteor.status()
if ((status === 'waiting') && (retryCount >= 5)) {
const interval = _.random(0, 1000 * 120)
Meteor.disconnect()
console.warn(`5 or more reconnection attempts. Reconnecting in ${interval} ms.`, Meteor.status())
Meteor.setTimeout(() => {
console.debug('Reconnecting...')
Meteor.reconnect()
}, interval)
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment