dsherret / dax

Cross-platform shell tools for Deno and Node.js inspired by zx.
MIT License
964 stars 33 forks source link

Redesign command and internal streams #224

Closed dsherret closed 5 months ago

dsherret commented 5 months ago

The current use of Deno.Reader and Deno.WriteSync internally is not working.

/** `Deno.Reader` stream. */
export interface Reader {
  read(p: Uint8Array): Promise<number | null>;
}

/** `Deno.WriterSync` stream. */
export interface WriterSync {
  writeSync(p: Uint8Array): number;
}

The writes could be going to stuff like writable streams and there needs to be a way to get backpressure.

Deno.WriteSync was used because it's fast and worked ok with the initial design, but it doesn't work well with WritableStreams, which must be async.

https://github.com/dsherret/dax/blob/c885ba58ba52035a6cf99629dbcac90209a94604/src/command.ts#L840

So, I'm going to change the interface internally to accept both a Writer or a WriterSync, then change the writes within a command to possibly return a promise. Doing a quick bench, conditionally awaiting the promise is 2x faster than always awaiting one.