cli-ux icon indicating copy to clipboard operation
cli-ux copied to clipboard

Flush never hits drain condition

Open devshorts opened this issue 4 years ago • 0 comments

It seems that flush should be checking the result of process.stdout.write to see if it was already flushed or not. For example

async function flush() {
    const p = new Promise(resolve => process.stdout.once('drain', () => resolve()));
    const flushed = process.stdout.write('');

    if(flushed) {
      return Promise.resolve()
    }

    return p;
  }

If it's NOT flushed, then wait for drain. Otherwise because it's already drained the event never seems to fire so the other promise.race always wins

devshorts avatar Jun 02 '21 22:06 devshorts