hhvm / hsl-experimental

Experimental features for the Hack Standard Library
MIT License
23 stars 10 forks source link

[wish] Make it easy to read line without end of line characters #113

Closed xixixao closed 4 years ago

xixixao commented 4 years ago

For:

interface ReadHandle extends Handle {
  /** Read until we reach `$max_bytes`, the end of the file, or the
   * end of the line.
   *
   * 'End of line' is platform-specific, and matches the C `fgets()`
   * function; the newline character/characters are included in the
   * return value. */
  public function readLineAsync(
    ?int $max_bytes = null,
    ?float $timeout_seconds = null,
  ): Awaitable<string>;

It would be nice to support an option (or better expose a separate method) that doesn't include the newline character(s) in the return value.

Alternatively we could provide a more generic way of removing one trailing newline, with correct cross-platform behavior.

fredemmott commented 4 years ago

FYI this will likely be unaddressed for a while:

fredemmott commented 4 years ago

so on doesn't really fit with async that well

To clarify a bit, this isn't hack-specific: this is true whenever O_NONBLOCK is set, regardless of the programming language used.

This is an issue here as HSL IO aims to be async-first, so O_NONBLOCK is /always/ set.

fredemmott commented 4 years ago

Fixed by that PR