What is the canonical name for a function that ensures that an asynchronous task takes at least x time to resolve?

71 Views Asked by At

Say we have an asynchronous function that may resolve within any duration. However fast it may be, we want to ensure it never resolves before t time as passed. To achieve this in a reusable way, we create a function (here in JavaScript):

async function stall(task, minDuration) {
  // Wait until both `task` and `delay(minDuration)` resolves
  // and return the results from `task`
  const results = await Promise.all([task, delay(minDuration)])
  return results[0]
}

where delay() is a simple function that resolves after a given amount of time.

Is there a canonical name for the stall() function?

0

There are 0 best solutions below