For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/function/flowAsync.md.

flowAsync

Creates an async pipeline that awaits each step before passing the result to the next function. Like flow from es-toolkit but async-aware.

Each function can return a value or a Promise — flowAsync always returns a Promise that resolves to the final step's awaited result.

const getUsername = flowAsync(
  (id: string) => fetchUser(id),  // Promise<User>
  (user) => user.name,            // string
  (name) => name.toUpperCase(),
)
await getUsername('123') // 'ALICE'

Usage

flowAsync(...functions)

Creates an async pipeline that awaits each step before passing the result to the next function. Like flow from es-toolkit but async-aware.

Each function can return a value or a Promise — flowAsync always returns a Promise that resolves to the final step's awaited result.

import { flowAsync } from 'massaman'
// or:  import { flowAsync } from 'massaman/function'

const getUsername = flowAsync(
  (id: string) => fetchUser(id),  // Promise<User>
  (user) => user.name,            // string
  (name) => name.toUpperCase(),
)
await getUsername('123') // 'ALICE'

Parameters

first(...args: A) => R1 | Promise<R1>required

the first pipeline function. It receives every argument passed to the composed function.

functionsArray<(value) => result | Promise<result>>required

the remaining pipeline functions. Each receives the awaited result of the previous function.

Returns

a composed function that always resolves to the awaited result of the final pipeline step.

(...args: A) => Promise<Awaited<R>>