lookup method
Finds a number of elements that have all the desired tags
.
If tags
is omitted or empty, any element of the registry can be
returned.
If max
is specified, it must be greater than zero.
In that case, at most the first max
results are returned,
in whatever order the registry finds its results.
Otherwise all matching elements are returned.
Implementation
Future<List<T>> lookup({Iterable<Object?>? tags, int? max}) async {
if (max != null && max < 1) {
throw RangeError.range(max, 1, null, 'max');
}
if (tags != null) tags = tags.toList(growable: false);
var completer = Completer<List<T>>();
var port = singleCompletePort(completer, callback: (List<T> response) {
// Response is even-length list of (id, element) pairs.
var cache = _cache;
var count = response.length ~/ 2;
var result = List<T>.generate(
count,
(i) =>
cache.register(response[i * 2] as int, response[i * 2 + 1]) as T,
growable: false);
return result;
}, timeout: _timeout);
_commandPort.send(list4(_findValue, tags, max, port));
return await completer.future;
}