1

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?

Alexander Wallin
  • 1,394
  • 10
  • 22
  • I've never encountered such a canonical convention in the countless APIs I've encountered (this is a somewhat unusual requirement as well in my experience), but often I see what you're calling `minDuration` as `timeout` at least in synchronous/blocking contexts. –  Dec 03 '18 at 03:36
  • I agree it is a bit quirky. It was used in a web app that simply felt too fast. – Alexander Wallin Dec 03 '18 at 15:09

0 Answers0