Merge pull request #445 from shocknet/bug/register-timeout
Fix create new alias TIMEOUT_ERR
This commit is contained in:
commit
8a35dd9ebd
1 changed files with 7 additions and 24 deletions
|
|
@ -538,40 +538,23 @@ const register = async (alias, pass) => {
|
||||||
|
|
||||||
if (theresPeers && !atLeastOneIsConnected) {
|
if (theresPeers && !atLeastOneIsConnected) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'No connected to any peers for checking of duplicate aliases'
|
'Not connected to any peers for checking of duplicate aliases'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theresPeers && atLeastOneIsConnected) {
|
if (theresPeers && atLeastOneIsConnected) {
|
||||||
// this import is done here to avoid circular dependency hell
|
|
||||||
const { timeout5 } = require('../contact-api/utils')
|
|
||||||
|
|
||||||
let userData = await timeout5(
|
|
||||||
new Promise(res => {
|
|
||||||
gun.get(`~@${alias}`).once(ud => res(ud))
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
if (userData) {
|
|
||||||
throw new Error(
|
|
||||||
'The given alias has been used before, use an unique alias instead.'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
await new Promise(res => setTimeout(res, 300))
|
await new Promise(res => setTimeout(res, 300))
|
||||||
|
|
||||||
userData = await timeout5(
|
const userData = await new Promise(res => {
|
||||||
new Promise(res => {
|
gun.get(`~@${alias}`).once(ud => res(ud), {
|
||||||
gun.get(`~@${alias}`).once(ud => res(ud), {
|
// https://github.com/amark/gun/pull/971#issue-438630761
|
||||||
// https://github.com/amark/gun/pull/971#issue-438630761
|
wait: 1500
|
||||||
wait: 1500
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
)
|
})
|
||||||
|
|
||||||
if (userData) {
|
if (userData) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'The given alias has been used before, use an unique alias instead. (Caught at 2nd try)'
|
'The given alias has been used before, use a unique alias instead. (Caught at 2nd try)'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue