Class: AsyncSearch

AsyncSearch()

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 start
  • Describe async expansion of candidates via space
  • Control exploration order with queue
  • Limit branching using max
  • Limit concurrency using cores, which can be dynamic at runtime

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()

Classes

AsyncSearch

Members

cores :number

Number of concurrent expansions per batch

Type:
  • number

max

Maximum queue size (selects the best max candidates).

queue

Queue controlling search order.

space

Expansion function describing the search space. Must be (candidate:any) => AsyncIterable|Iterable|Promise<Iterable>|undefined.

start

Initial candidates (or Promises or AsyncEach of candidates) to seed the search.

Methods

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

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

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