requestRelays method
Implementation
Future<NdkResponse> requestRelays(
String name,
Iterable<String> urls,
Filter filter, {
Duration timeout = kDefaultStreamIdleTimeout,
bool closeOnEOSE = true,
}) async {
String id = Helpers.getRandomString(10);
RequestState state = RequestState(closeOnEOSE
? NdkRequest.query(
id,
name: name,
filters: [filter],
timeoutDuration: timeout,
)
: NdkRequest.subscription(
id,
name: name,
filters: [],
));
for (var url in urls) {
state.addRequest(url, RelaySet.sliceFilterAuthors(filter));
}
_globalState.inFlightRequests[state.id] = state;
List<String> notSent = [];
for (MapEntry<String, RelayRequestState> entry in state.requests.entries) {
if (!doRelayRequest(state.id, entry.value)) {
notSent.add(entry.key);
}
}
for (var url in notSent) {
state.requests.remove(url);
}
return NdkResponse(state.id, state.stream);
}