requestRelays method
Implementation
Future<NdkResponse> requestRelays(
String name, Iterable<String> urls, Filter filter,
{int timeout = DEFAULT_STREAM_IDLE_TIMEOUT,
bool closeOnEOSE = true,
Function()? onTimeout}) async {
String id = Helpers.getRandomString(10);
RequestState state = RequestState(closeOnEOSE
? NdkRequest.query(id, name: name, filters: [filter])
: 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);
}