remove rethrows and seemingly uneeded configure

pull/1189/head
Ryan Tharp 5 years ago
parent 3d7b36aa57
commit f6525862d4

@ -1,12 +1,7 @@
/* global clearTimeout */ /* global clearTimeout, log */
// was timeoutDelay // was timeoutDelay
const sleepFor = ms => new Promise(resolve => setTimeout(resolve, ms)); const sleepFor = ms => new Promise(resolve => setTimeout(resolve, ms));
let log;
function configure(options = {}) {
({ log } = options);
}
// Taken from https://stackoverflow.com/questions/51160260/clean-way-to-wait-for-first-true-returned-by-promise // Taken from https://stackoverflow.com/questions/51160260/clean-way-to-wait-for-first-true-returned-by-promise
// The promise returned by this function will resolve true when the first promise // The promise returned by this function will resolve true when the first promise
// in ps resolves true *or* it will resolve false when all of ps resolve false // in ps resolves true *or* it will resolve false when all of ps resolve false
@ -73,17 +68,7 @@ async function allowOnlyOneAtATime(name, process, timeout) {
} }
let outerRetval; let outerRetval;
// handle any timeouts // handle any timeouts
try { outerRetval = await snodeGlobalLocks[name];
outerRetval = await snodeGlobalLocks[name];
} catch (e) {
// we will throw for each time allowOnlyOneAtATime has been called in parallel
log.error(
'loki_primitives:::allowOnlyOneAtATime - error',
e.code,
e.message
);
throw e;
}
return outerRetval; return outerRetval;
} }
@ -110,15 +95,8 @@ function abortableIterator(array, iterator) {
let item = destructableList.pop(); let item = destructableList.pop();
while (item && !abortIteration) { while (item && !abortIteration) {
if (serially) { if (serially) {
try { // eslint-disable-next-line no-await-in-loop
// eslint-disable-next-line no-await-in-loop accum.push(await iterator(item));
accum.push(await iterator(item));
} catch (e) {
log.error(
`loki_primitives:::abortableIterator - error ${e.code} ${e.message}`
);
throw e;
}
} else { } else {
accum.push(iterator(item)); accum.push(iterator(item));
} }
@ -127,18 +105,12 @@ function abortableIterator(array, iterator) {
return accum; return accum;
}, },
stop: () => { stop: () => {
/*
log.debug('loki_primitives:::abortableIterator - Stopping',
destructableList.length, '+', accum.length, '=', array.length,
'aborted?', abortIteration);
*/
controlResolveFunctor(); controlResolveFunctor();
}, },
}; };
} }
module.exports = { module.exports = {
configure,
sleepFor, sleepFor,
allowOnlyOneAtATime, allowOnlyOneAtATime,
abortableIterator, abortableIterator,

Loading…
Cancel
Save