Better log

This commit is contained in:
Daniel Lugo 2021-09-16 11:14:25 -04:00
parent fc7e76036a
commit b3a9765b7b

View file

@ -246,15 +246,17 @@ const forge = () => {
throw new Error('Double forge?') throw new Error('Double forge?')
} }
/** Used only for logs. */
const isReforge = !!currentGun
logger.info(isReforge ? 'Will reforge' : 'Will forge')
isForging = true isForging = true
if (currentGun) { if (currentGun) {
logger.info('Will reforge')
currentGun.off('message', handleMsg) currentGun.off('message', handleMsg)
currentGun.disconnect() currentGun.disconnect()
currentGun.kill() currentGun.kill()
logger.info('Killed current gun') logger.info('Destroyed current gun')
} else {
logger.info('Will forge')
} }
const newGun = fork('utils/GunSmith/gun.js') const newGun = fork('utils/GunSmith/gun.js')
currentGun = newGun currentGun = newGun
@ -283,7 +285,12 @@ const forge = () => {
} }
return msg return msg
}) })
currentGun.send(lastGunListeners)
if (lastGunListeners.length) {
currentGun.send(lastGunListeners)
logger.info(`Sent ${lastGunListeners.length} pending on() listeners`)
}
const lastGunMapListeners = Object.keys(pathToMapListeners).map(path => { const lastGunMapListeners = Object.keys(pathToMapListeners).map(path => {
/** @type {Smith.SmithMsgMapOn} */ /** @type {Smith.SmithMsgMapOn} */
@ -293,15 +300,24 @@ const forge = () => {
} }
return msg return msg
}) })
currentGun.send(lastGunMapListeners)
logger.info('Sent pending map.on listeners') if (lastGunMapListeners.length) {
currentGun.send(lastGunMapListeners)
logger.info('Finished reforging, will now auto-auth') logger.info(
`Sent ${lastGunMapListeners.length} pending map().on() listeners`
)
}
autoAuth().then(() => { if (isReforge) {
logger.info('Finished reforging, will now auto-auth')
autoAuth().then(() => {
isForging = false
})
} else {
logger.info('Finished forging, will now auto-auth')
isForging = false isForging = false
}) }
} }
/** /**