runBrudcastHandler<T> function

Future<T> runBrudcastHandler<T>(
  1. String name,
  2. FutureOr<T> handler(),
  3. T fallback
)

Runs a host handler, answering fallback when it throws or does not answer within brudcastHandlerTimeout, so a faulty handler never stalls a message, a notification or a link.

name names the handler in the warning logged on a fallback.

Implementation

Future<T> runBrudcastHandler<T>(String name, FutureOr<T> Function() handler, T fallback) async {
  try {
    return await Future<T>.sync(handler).timeout(brudcastHandlerTimeout);
  } on TimeoutException {
    BrudcastLog.warning('The $name did not answer within two seconds; the default is used');
    return fallback;
  } catch (error) {
    BrudcastLog.error('The $name threw: $error');
    return fallback;
  }
}