send method
Sends event to bloc and waits until every bloc is idle — the run
it starts, every reaction that follows from it, and every run those
start. Fails as settle fails; rethrows what the send's own future
failed with (an error handler that threw). An event with no use case
does not fail the send: it is recorded as an error, for
expectErrors.
Implementation
Future<void> send(
JuiceBloc<BlocState> bloc,
EventBase event, {
Duration timeout = defaultTimeout,
}) async {
_checkRunning();
return _call(() async {
Object? error;
StackTrace? stackTrace;
final sent = bloc.send(event).then<void>((_) {}, onError: (Object e, s) {
error = e;
stackTrace = s as StackTrace;
});
await settle(timeout: timeout);
await sent;
if (error != null) Error.throwWithStackTrace(error!, stackTrace!);
});
}