I would like to create a matcher that takes async or non-async callback, sets up some listeners, invokes callback, verifies listeners received expected events, and then clean up listeners.
However, I see couple blockers:
Matcher.matches
is syncIs it possible at all to create what I want?
I ended up creating a helper async method events
that takes the callback as parameter, configures listeners, invokes callback, cleans up listeners, an returns the list of the collected events. And then matcher analyses the list synchronously:
await expectLater(
await events(() async {...}), areInRightSequence,
);