Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Array.fromAsync when Node.js 22.x becomes the minimum supported version #315

Open
kamiazya opened this issue Aug 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@kamiazya
Copy link
Owner

kamiazya commented Aug 9, 2024

Overview

Currently, the convertThisAsyncIterableIteratorToArray function manually iterates over an asynchronous generator to convert its output into an array. This is done because the project does not yet support Node.js 22.x, where the Array.fromAsync method is available.

export async function convertThisAsyncIterableIteratorToArray<
  O,
  T extends (...args: any[]) => AsyncGenerator<O>,
>(this: T, ...args: Parameters<T>): Promise<O[]> {
  // TODO: Use Array.fromAsync when Node.js 22.x becomes the minimum supported version.
  // return Array.fromAsync(this(...args));
  const rows: O[] = [];
  for await (const row of this(...args)) {
    rows.push(row);
  }
  return rows;
}

Once the project moves to Node.js 22.x as the minimum supported version, update this function to use Array.fromAsync for converting the asynchronous generator to an array. This will simplify the code and take advantage of the newer, built-in API.

@kamiazya kamiazya added the enhancement New feature or request label Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant