Skip to content

Add something like Promise.allKeyed and Promise.allSettledKeyed to @std/async #6863

@lionel-rowe

Description

@lionel-rowe

Is your feature request related to a problem? Please describe.

Add something like Promise.allKeyed/Promise.allSettledKeyed to @std/async, which is more ergonomic than all/allSettled for many use cases.

Per Await dictionary of Promises proposal § Motivation:

  • await on individual properties creates a waterfall, rather than running requests in parallel
  • Promise.all helps, but is based on order, rather than names, which could lead to mixups
  • Solutions using existing syntax can be verbose and pollute the number of variables in scope

Prior art:

Describe the solution you'd like

Something like this:

type Promises<T extends Record<string, unknown>> = {
    [P in keyof T]: Promise<T[P]> | T[P]
}
type PromisesSettled<T extends Record<string, unknown>> = {
    [P in keyof T]: PromiseSettledResult<T[P]>
}

export declare function promiseAllKeyed<T extends Record<string, unknown>>(
    promises: Promises<T>,
): Promise<T>

export function promiseAllSettledKeyed<T extends Record<string, unknown>>(
    promises: Promises<T>,
): Promise<PromisesSettled<T>>

Describe alternatives you've considered

Naming — promiseAllKeyed? promiseAllProperties? promiseHash? promiseObj? etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions