Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions async/unstable_all_keyed.ts → async/all_keyed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export type SettledRecord<T extends Record<PropertyKey, unknown>> = {
* {@link https://github.com/tc39/proposal-await-dictionary | Await Dictionary}
* proposal (`Promise.allKeyed`).
*
* @experimental **UNSTABLE**: New API, yet to be vetted.
*
* @typeParam T The record shape with resolved (unwrapped) value types. For
* example, if passing `{ foo: Promise<number> }`, `T` would be `{ foo: number }`.
* @param record A record where values are promise-like (thenables) or plain values.
Expand All @@ -57,7 +55,7 @@ export type SettledRecord<T extends Record<PropertyKey, unknown>> = {
*
* @example Basic usage
* ```ts
* import { allKeyed } from "@std/async/unstable-all-keyed";
* import { allKeyed } from "@std/async/all-keyed";
* import { assertEquals } from "@std/assert";
*
* const result = await allKeyed({
Expand All @@ -70,7 +68,7 @@ export type SettledRecord<T extends Record<PropertyKey, unknown>> = {
*
* @example Parallel HTTP requests
* ```ts no-assert ignore
* import { allKeyed } from "@std/async/unstable-all-keyed";
* import { allKeyed } from "@std/async/all-keyed";
*
* const { user, posts } = await allKeyed({
* user: fetch("/api/user").then((r) => r.json()),
Expand All @@ -80,7 +78,7 @@ export type SettledRecord<T extends Record<PropertyKey, unknown>> = {
*
* @example Mixed promises and plain values
* ```ts
* import { allKeyed } from "@std/async/unstable-all-keyed";
* import { allKeyed } from "@std/async/all-keyed";
* import { assertEquals } from "@std/assert";
*
* const result = await allKeyed({
Expand Down Expand Up @@ -124,8 +122,6 @@ export function allKeyed<T extends Record<PropertyKey, unknown>>(
* {@link https://github.com/tc39/proposal-await-dictionary | Await Dictionary}
* proposal (`Promise.allSettledKeyed`).
*
* @experimental **UNSTABLE**: New API, yet to be vetted.
*
* @typeParam T The record shape with resolved (unwrapped) value types. For
* example, if passing `{ foo: Promise<number> }`, `T` would be `{ foo: number }`.
* @param record A record where values are promise-like (thenables) or plain values.
Expand All @@ -134,7 +130,7 @@ export function allKeyed<T extends Record<PropertyKey, unknown>>(
*
* @example Basic usage
* ```ts
* import { allSettledKeyed } from "@std/async/unstable-all-keyed";
* import { allSettledKeyed } from "@std/async/all-keyed";
* import { assertEquals } from "@std/assert";
*
* const settled = await allSettledKeyed({
Expand All @@ -148,7 +144,7 @@ export function allKeyed<T extends Record<PropertyKey, unknown>>(
*
* @example Error handling
* ```ts
* import { allSettledKeyed } from "@std/async/unstable-all-keyed";
* import { allSettledKeyed } from "@std/async/all-keyed";
* import { assertEquals, assertExists } from "@std/assert";
*
* const settled = await allSettledKeyed({
Expand Down
24 changes: 23 additions & 1 deletion async/unstable_all_keyed_test.ts → async/all_keyed_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2026 the Deno authors. MIT license.
import { allKeyed, allSettledKeyed } from "./unstable_all_keyed.ts";
import { allKeyed, allSettledKeyed } from "./all_keyed.ts";
import {
assertEquals,
assertFalse,
Expand Down Expand Up @@ -195,3 +195,25 @@ Deno.test("allKeyed() ignores non-enumerable symbol keys", async () => {
assertEquals(Object.keys(result), ["visible"]);
assertFalse(sym in result);
});

Deno.test("allKeyed() resolves custom thenables", async () => {
const thenable = {
then(resolve: (value: number) => void) {
resolve(99);
},
} as PromiseLike<number>;
const result = await allKeyed({ val: thenable });

assertEquals(result.val, 99);
});

Deno.test("allSettledKeyed() resolves custom thenables", async () => {
const thenable = {
then(resolve: (value: string) => void) {
resolve("from thenable");
},
} as PromiseLike<string>;
const result = await allSettledKeyed({ val: thenable });

assertEquals(result.val, { status: "fulfilled", value: "from thenable" });
});
2 changes: 1 addition & 1 deletion async/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"./pool": "./pool.ts",
"./retry": "./retry.ts",
"./tee": "./tee.ts",
"./all-keyed": "./all_keyed.ts",
"./unstable-abortable": "./unstable_abortable.ts",
"./unstable-throttle": "./unstable_throttle.ts",
"./unstable-wait-for": "./unstable_wait_for.ts",
"./unstable-semaphore": "./unstable_semaphore.ts",
"./unstable-circuit-breaker": "./unstable_circuit_breaker.ts",
"./unstable-lazy": "./unstable_lazy.ts",
"./unstable-all-keyed": "./unstable_all_keyed.ts",
"./unstable-poll": "./unstable_poll.ts",
"./unstable-pool-settled": "./unstable_pool_settled.ts",
"./unstable-channel": "./unstable_channel.ts"
Expand Down
1 change: 1 addition & 0 deletions async/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export * from "./mux_async_iterator.ts";
export * from "./pool.ts";
export * from "./tee.ts";
export * from "./retry.ts";
export * from "./all_keyed.ts";
Loading