async function time(f) {
  const clock = sinon.useFakeTimers() // Will only advance automatically if runAll() doesn't work.

  // Run the function
  let done = false;
  (async () => {
    await handleLater(f) // await f to either resolve or reject
    done = true
  })()

  // Run the clock, allowing the function's delays to complete
  while (!done) {
    clock.runAll() // Even though it's called 'runAll', calling it multiple times is necessary
    await Promise.resolve() // Yield to the function that's running
  }

  // Finish up
  const end = new Date().getTime()
  clock.restore()
  return end
}
// Time how long it takes an async function to complete without actually waiting that long. Returns a promise that resolves to the # of ms.
Time how long it takes an async function to complete without actually waiting that long. Returns a promise that resolves to the # of ms.
Time how long it takes an async function to complete without actually waiting that long . Returns a promise that resolves to the # of ms .
async function time(f) {
  const clock = sinon.useFakeTimers() 
  let done = false;
  (async () => {
    await handleLater(f) 
    done = true
  })()
  while (!done) {
    clock.runAll() 
    await Promise.resolve() 
  }
  const end = new Date().getTime()
  clock.restore()
  return end
}
async function time ( f ) { const clock = sinon . useFakeTimers ( ) let done = false ; ( async ( ) => { await handleLater ( f ) done = true } ) ( ) while ( ! done ) { clock . runAll ( ) await Promise . resolve ( ) } const end = new Date ( ) . getTime ( ) clock . restore ( ) return end }
Time how long it takes an async function to complete without actually waiting that long.
Time how long it takes an async function to complete without actually waiting that long .
// Will only advance automatically if runAll() doesn't work. // Run the function // await f to either resolve or reject // Run the clock, allowing the function's delays to complete // Even though it's called 'runAll', calling it multiple times is necessary // Yield to the function that's running // Finish up