Skip to main content

Find One Async

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
optionsOmit<FindOptions<T>, 'data'>Search configuration

Returns

Promise<T | undefined> - First matching item or undefined

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

Examples

const result = await finder.findOneAsync(
() => fetchUsersFromAPI(),
'admin',
'role'
);

With Caching

const user = await finder.findOneAsync(
() => db.query('SELECT * FROM users'),
'john@example.com',
'email',
{ cacheKey: 'john-search' }
);

Notes

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

See Also