import '../model/account_data.dart'; /// Joins concurrent calls into the one already running for the same account /// session. A run left over from a signed-out session never blocks the next /// account's first call. class SessionSingleFlight { Future? _running; int? _epoch; Future run(Future Function() action) { final epoch = AccountData().sessionEpoch; final running = _running; if (running != null && _epoch == epoch) return running; _epoch = epoch; late final Future current; current = action().whenComplete(() { if (identical(_running, current)) _running = null; }); return _running = current; } }