Skip to content

tapAsync

tapAsync<A>(fn, options?): (a) => A

Defined in: Composition/tap.ts:142

Triggers a fire-and-forget asynchronous side effect in the background, returning the piped value immediately and synchronously. Calls the function immediately. Synchronous throws and promise rejections are forwarded to onError, which defaults to console.error and must not throw.

A

(a) => Thenable<unknown>

Options

(a) => A

const user = { id: 1 };
const saveToDatabase = async (u: typeof user) => {};
const logError = (err: unknown) => console.error(err);

pipe(
  user,
  tapAsync(async (u) => {
    await saveToDatabase(u);
  }, { onError: (err) => logError(err) })
);