registerPendingOperation method
Registers a new pending operation and returns a new function that can be used to signal that the pending operation has completed.
The returned function is safe to be used before return
statements.
Implementation
void Function() registerPendingOperation(String description) {
_pendingCalls++;
_ongoingOperations.add(description);
final completer = Completer<void>();
_knownCallsHandled = [..._knownCallsHandled, completer.future];
// Guard that the `done` callback runs only once
var done = false;
return () => Timer.run(
() {
if (done) {
assert(
false,
'Tried running completer function twice. Operation: $description',
);
return;
}
done = true;
_ongoingOperations.remove(description);
_pendingCalls--;
completer.complete();
},
);
}