Better forge
This commit is contained in:
parent
956fa6dcff
commit
ed3bab0f8e
1 changed files with 27 additions and 14 deletions
|
|
@ -240,7 +240,7 @@ const isReady = () =>
|
|||
|
||||
let procID = 0
|
||||
|
||||
const forge = () => {
|
||||
const forge = async () => {
|
||||
logger.info(`Forging Gun # ${++procID}`)
|
||||
if (isForging) {
|
||||
throw new Error('Double forge?')
|
||||
|
|
@ -274,8 +274,18 @@ const forge = () => {
|
|||
opts: lastOpts,
|
||||
type: 'init'
|
||||
}
|
||||
await new Promise(res => {
|
||||
currentGun.on('message', msg => {
|
||||
if (msg.type === 'init') {
|
||||
// @ts-ignore
|
||||
res()
|
||||
}
|
||||
})
|
||||
currentGun.send(initMsg)
|
||||
logger.info('Sent init msg')
|
||||
})
|
||||
|
||||
logger.info('Received init reply')
|
||||
|
||||
const lastGunListeners = Object.keys(pathToListeners).map(path => {
|
||||
/** @type {Smith.SmithMsgOn} */
|
||||
|
|
@ -309,17 +319,20 @@ const forge = () => {
|
|||
)
|
||||
}
|
||||
|
||||
if (isReforge) {
|
||||
logger.info('Finished reforging, will now auto-auth')
|
||||
autoAuth().then(() => {
|
||||
logger.info(
|
||||
isReforge
|
||||
? 'Finished reforging, will now auto-auth'
|
||||
: 'Finished forging, will now auto-auth'
|
||||
)
|
||||
|
||||
await autoAuth()
|
||||
|
||||
// Eslint disable: This should be caught by a if (isForging) {throw} at the
|
||||
// beginning of this function
|
||||
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
isForging = false
|
||||
flushPendingPuts()
|
||||
})
|
||||
} else {
|
||||
logger.info('Finished forging, will now auto-auth')
|
||||
isForging = false
|
||||
flushPendingPuts()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue