Toolbox-XToolbox-X

Find One Item Async

Asynchronously finds the first matching item using the same search strategies as findOne().

findOneAsync()

Asynchronously finds the first matching item using the same search strategies as findOne().

Signature

async findOneAsync(
  supplier: () => Promise<T[]>,
  matcher: string | number,
  keySelector: KeySelector<T>,
  options?: Omit<FindOptions<T>, 'data'>
): Promise<T | undefined>

Parameters

ParameterTypeDescription
supplier() => Promise<T[]>Async function providing the data.
matcherstring | numberValue to match against.
keySelectorKeySelector<T>Property name or value extractor function.
optionsOmit<FindOptions<T>, 'data'>Search configuration options (excluding data).

Returns

Promise<T | undefined> — First matching item or undefined if none found.

Description

This method provides an async interface to findOne(), useful when:

  • Data needs to be loaded asynchronously.
  • Working with dynamic datasets.
  • Integrating with async data sources.

Example Usage

import { Finder } from 'toolbox-x';

interface User {
  id: number;
  name: string;
  role: string;
}

const userFinder = new Finder<User>([]);

// Basic Async Search
const result = await userFinder.findOneAsync(
  async () => [
    { id: 1, name: 'Alice', role: 'admin' },
    { id: 2, name: 'Bob', role: 'user' }
  ],
  'admin',
  'role'
);

console.log(result);

Notes

  • Inherits all search behaviors from findOne().
  • Supports same caching and matching options.
  • Automatically awaits data before searching.
  • Rejects if supplier throws an error.

Last updated: Mon, Jun 15, 2026 06:09:51AM (UTC)

On this page