From c08e2151e833a7760046f968513090a0c9ad7662 Mon Sep 17 00:00:00 2001 From: Tomasz Szuba Date: Wed, 29 Nov 2023 09:08:06 +0100 Subject: [PATCH] Fix review comments Signed-off-by: Tomasz Szuba --- .../src/processing/TaskPipeline.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/catalog-backend/src/processing/TaskPipeline.ts b/plugins/catalog-backend/src/processing/TaskPipeline.ts index 98cf221b6e..b808e41ce4 100644 --- a/plugins/catalog-backend/src/processing/TaskPipeline.ts +++ b/plugins/catalog-backend/src/processing/TaskPipeline.ts @@ -89,11 +89,11 @@ export function startTaskPipeline(options: Options) { async function pipelineLoop() { while (!abortSignal.aborted) { - await withActiveSpan(tracer, 'TaskPipelineLoop', async span => { - if (state.inFlightCount <= lowWatermark) { + if (state.inFlightCount <= lowWatermark) { + await withActiveSpan(tracer, 'TaskPipelineLoop', async span => { const loadCount = highWatermark - state.inFlightCount; - const loadedItems = await Promise.resolve(loadCount) - .then(loadTasks) + const loadedItems = await Promise.resolve() + .then(() => loadTasks(loadCount)) .catch(() => { // Silently swallow errors and go back to sleep to try again; we // delegate to the loadTasks function itself to catch errors and log @@ -104,8 +104,8 @@ export function startTaskPipeline(options: Options) { if (loadedItems.length && !abortSignal.aborted) { state.inFlightCount += loadedItems.length; for (const item of loadedItems) { - Promise.resolve(item) - .then(processTask) + Promise.resolve() + .then(() => processTask(item)) .catch(() => { // Silently swallow errors and go back to sleep to try again; we // delegate to the processTask function itself to catch errors @@ -117,8 +117,8 @@ export function startTaskPipeline(options: Options) { }); } } - } - }); + }); + } await barrier.wait(); } }