Skip to content

Commit

Permalink
Resolve the nightscout URL before closing previous socket connection
Browse files Browse the repository at this point in the history
Otherwise there's a race condition where there's no socket for
a little while, allowing multiple sockets to be created at the
same time leading to strange results (delta of 0 consistently)
  • Loading branch information
TooTallNate committed Jan 18, 2018
1 parent 39ebe96 commit 3df5d03
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bin/nightscout-ps1-daemon.js
Expand Up @@ -140,12 +140,13 @@ async function onDataUpdate(event) {
}

async function main() {
const nightscout = await resolvedNightscout

if (socket) {
debug('socket.close()')
socket.close()
}

const nightscout = await resolvedNightscout
debug('Creating socket.io connection %o', nightscout)
socket = sio.connect(nightscout)
socket.on('dataUpdate', e => exit(onDataUpdate(e)))
Expand Down

0 comments on commit 3df5d03

Please sign in to comment.