firstEvent<T> method
Future<T?>
firstEvent<T>(
- dynamic responseHandler(
- T
- Duration? timeout = const Duration(seconds: 5),
Implementation
Future<T?> firstEvent<T>(Function(T) responseHandler, {Duration? timeout = const Duration(seconds: 5)}) {
if (timeout != null) {
return firstWhere((element) => element is T).timeout(
timeout,
onTimeout: () {
return Future<T>.error("Timeout waiting for event of type $T");
},
).then((e) => responseHandler(e));
} else {
return firstWhere((element) => element is T).then((e) => responseHandler(e));
}
}