Class: AsyncSearch

AsyncSearch(startopt, spaceopt, queueopt, maxopt, coresopt)

Base class for defining declarative, asynchronous lazy algorithms.

AsyncSearch defines a process that can span multiple machines, exploring candidate solutions via asynchronous lazy iteration. Candidates are produced on-demand through a local queue, while the expansion function may execute asynchronously across different machines.

Features:

  • Define initial candidates via from
  • Describe asynchronous expansion of candidates via through
  • Control exploration order with via
  • Limit branching using max
  • Limit concurrency using inParallel

Internally, the search iterates in batches of candidates, each up to cores in size, which are expanded in parallel. Through [Symbol.asyncIterator](), AsyncSearch yields individual candidates in a flattened stream, maintaining semantic consistency with the synchronous Search.

Candidate transformation and iteration termination are fluent, leveraging methods from AsyncEach.

Constructor

new AsyncSearch(startopt, spaceopt, queueopt, maxopt, coresopt)

Create a new AsyncSearch instance.

Parameters:
Name Type Attributes Default Description
start Iterable | AsyncIterable | Promise.<Iterable> <optional>

Initial candidates.

space function <optional>

Expansion function.

queue Object <optional>

Queue instance controlling iteration order.

max number <optional>

Maximum queue size.

cores number <optional>
16

Number of concurrent expansions per batch.

Classes

AsyncSearch

Members

cores :number

Number of concurrent expansions per batch.

Type:
  • number

max :number|undefined

Maximum queue size (limits branching).

Type:
  • number | undefined

queue :Object

Queue controlling search order (BFS, DFS, priority, etc.). Must implement .addAll(), .poll(), .clear(), .n(), and optionally .select().

Type:
  • Object

space :function|undefined

Expansion function describing the search space. Should return an async iterable, iterable, or promise resolving to an iterable.

Type:
  • function | undefined

start :Iterable|AsyncIterable|Promise.<Iterable>|undefined

Initial candidates to seed the search. Can be an array, an async iterable, a promise, or an AsyncEach instance.

Type:
  • Iterable | AsyncIterable | Promise.<Iterable> | undefined

Methods

(async, generator) batchIterator() → {Array.<any>}

Lazily iterate over candidates asynchronously in batches. Each batch contains up to cores candidates.

Throws:

If the expansion function fails or returns invalid data.

Type
Error
Yields:
A batch of candidates.
Type
Array.<any>

from(…starts) → {AsyncSearch}

Define the starting candidates for the search.

Parameters:
Name Type Attributes Description
starts * <repeatable>

One or more initial candidates.

Returns:

The current search instance (for chaining).

Type
AsyncSearch

inParallel(cores) → {AsyncSearch}

Define the concurrency level (number of candidates processed in parallel).

Parameters:
Name Type Description
cores number

Number of concurrent expansions.

Returns:

The current search instance (for chaining).

Type
AsyncSearch

through(space) → {AsyncSearch}

Define the asynchronous expansion logic (search space).

Parameters:
Name Type Description
space function

Function describing the search space.

Returns:

The current search instance (for chaining).

Type
AsyncSearch

via(queue, maxopt) → {AsyncSearch}

Define the queue strategy and optionally set a new maximum size.

Parameters:
Name Type Attributes Description
queue Object

Queue implementation controlling exploration order.

max number <optional>

Optional new maximum queue size.

Returns:

The current search instance (for chaining).

Type
AsyncSearch