ensure method

Future<void> ensure(
  1. FutureOr<void> fn()?
)

Ensures the signal is initialized and runs the given function.

Parameters:

  • fn: Optional function to run after ensuring initialization

Returns: A Future that completes when the operation is done

Implementation

Future<void> ensure(FutureOr<void> Function()? fn) async {
  if (!hasInitialized) await _load();

  await fn?.call();
}