runBoundedNonCritical function

Future<void> runBoundedNonCritical(
  1. Future<void> work(), {
  2. required Duration timeout,
  3. required String label,
})

Runs non-critical work inside a bootstrap hook with a hard timeout, swallowing any failure (a throw OR the timeout) so it can NEVER abort or stall the bootstrap.

dreamic-core treats an app hook's throw as fatal (it does not wrap hooks), and a hook that hangs stalls the whole bootstrap until the outer bootstrapTimeout. Work that is NOT required for the app to start — e.g. App Check activation (attested calls fetch a token lazily later), an analytics warm-up, a timezone service — should be wrapped here so a slow/locked/failed dependency degrades to "continue boot" instead of an init-error or a hang. This is the reusable form of the "app wraps its own non-critical hook work" contract: the mechanism lives in dreamic; the policy (which work is non-critical) stays with the app at the call site.

On timeout or failure the error is reported via reportBootstrapDiagnostic — so it reaches the backend whether the reporter attached before Firebase (Sentry early-attach) or after (Crashlytics; deferred + flushed on attach) — tagged with label for context, then this returns normally. The underlying work Future is not cancelled (Dart cannot), so it keeps running in the background — the desired behavior for fire-and-settle setup whose in-flight call completes shortly after.

NOTE: dreamic now owns App Check activation directly (see AppCheckConfig / the appCheck bootstrap param), so apps no longer need to wrap it here; this remains for any other non-critical post-init work (analytics warm-up, a timezone service, etc.).

Implementation

Future<void> runBoundedNonCritical(
  Future<void> Function() work, {
  required Duration timeout,
  required String label,
}) async {
  try {
    await work().timeout(timeout);
  } catch (e, st) {
    reportBootstrapDiagnostic(
      e,
      'Non-critical bootstrap work "$label" timed out or failed — continuing boot',
      st,
    );
  }
}