runWithoutAppOpen<T> method

Future<T> runWithoutAppOpen<T>(
  1. Future<T> action(), {
  2. String reason = 'scoped_action',
  3. Duration timeout = _defaultBlockerTimeout,
  4. Duration releaseDelay = const Duration(seconds: 1),
})

Convenience: run any async action with app-open ads suppressed. Guaranteed to unblock even if the action throws.

Implementation

Future<T> runWithoutAppOpen<T>(
  Future<T> Function() action, {
  String reason = 'scoped_action',
  Duration timeout = _defaultBlockerTimeout,

  /// Small grace period after the action completes — covers the
  /// resume animation/lifecycle callback that fires *after* the
  /// picker/camera returns.
  Duration releaseDelay = const Duration(seconds: 1),
}) async {
  blockAppOpen(reason, timeout: timeout);
  try {
    return await action();
  } finally {
    Future.delayed(releaseDelay, () => unblockAppOpen(reason));
  }
}