crawlAsync<K extends Object, V> function

Stream<V> crawlAsync<K extends Object, V>(
  1. Iterable<K> roots,
  2. FutureOr<V> readNode(
    1. K
    ),
  3. FutureOr<Iterable<K>> edges(
    1. K,
    2. V
    )
)

Finds and returns every node in a graph who's nodes and edges are asynchronously resolved.

Cycles are allowed. If this is an undirected graph the edges function may be symmetric. In this case the roots may be any node in each connected graph.

V is the type of values in the graph nodes. K must be a type suitable for using as a Map or Set key. edges should return the next reachable nodes.

There are no ordering guarantees. This is useful for ensuring some work is performed at every node in an asynchronous graph, but does not give guarantees that the work is done in topological order.

If readNode returns null for any key it will be ignored from the rest of the graph. If missing nodes are important they should be tracked within the readNode callback.

If either readNode or edges throws the error will be forwarded through the result stream and no further nodes will be crawled, though some work may have already been started.

Crawling is eager, so calls to edges may overlap with other calls that have not completed. If the edges callback needs to be limited or throttled that must be done by wrapping it before calling crawlAsync.

Implementation

Stream<V> crawlAsync<K extends Object, V>(
    Iterable<K> roots,
    FutureOr<V> Function(K) readNode,
    FutureOr<Iterable<K>> Function(K, V) edges) {
  final crawl = _CrawlAsync(roots, readNode, edges)..run();
  return crawl.result.stream;
}