forked from snxraven/p2ns
Updates
This commit is contained in:
@@ -49,6 +49,24 @@ async function ensureDnsPassOpen(pass) {
|
||||
return true;
|
||||
}
|
||||
|
||||
async function waitForAutobaseIdle(pass, timeoutMs = 5000) {
|
||||
const base = pass && pass.base;
|
||||
if (!base) return false;
|
||||
|
||||
const start = Date.now();
|
||||
while (Date.now() - start < timeoutMs) {
|
||||
const flushing = typeof base._flushing === 'number' ? base._flushing > 0 : false;
|
||||
const fastForwarding = typeof base.isFastForwarding === 'function' ? base.isFastForwarding() : false;
|
||||
if (!base.updating && !base.appending && !flushing && !fastForwarding && !base.closing) {
|
||||
return true;
|
||||
}
|
||||
await sleep(100);
|
||||
}
|
||||
|
||||
logWarn('DnsPassQueue', 'Autobase did not become idle before dnsPass operation; proceeding cautiously');
|
||||
return false;
|
||||
}
|
||||
|
||||
function enqueueDnsPass(operation) {
|
||||
const run = chain.then(async () => {
|
||||
state.dnsPassWriteInProgress = (state.dnsPassWriteInProgress || 0) + 1;
|
||||
@@ -82,6 +100,7 @@ async function createInvite(pass, opts) {
|
||||
if (!(await ensureDnsPassOpen(pass))) {
|
||||
throw new Error('dnsPass not open');
|
||||
}
|
||||
await waitForAutobaseIdle(pass);
|
||||
logDebug('DnsPassQueue', 'createInvite: starting');
|
||||
try {
|
||||
return await withTimeout(
|
||||
|
||||
Reference in New Issue
Block a user