serializeCalls function

  1. @visibleForTesting
Future<void> Function(MethodCall call) serializeCalls(
  1. Future<void> handler(
    1. MethodCall call
    )
)

Runs handler for one call at a time, in arrival order, so an async initCallback finishes before the first location reaches the callback.

Implementation

@visibleForTesting
Future<void> Function(MethodCall) serializeCalls(
  Future<void> Function(MethodCall) handler,
) {
  Future<void> previous = Future<void>.value();
  return (MethodCall call) {
    final Future<void> current = previous.then((_) => handler(call));
    // A failing callback must not block the calls queued after it.
    previous = current.catchError((Object _) {});
    return current;
  };
}