asap<T> method

FutureOr<T> asap<T>(
  1. T computation(), {
  2. bool condition()?,
})

Executes the given computation as soon as possible, optionally based on a condition.

If the condition is provided and evaluates to true, the computation will be executed immediately. Otherwise, it will be executed after the current event loop has completed.

Example:

await Get.asap(() {
  // Some synchronous computation
});

If a condition is provided:

await Get.asap(() {
  // Some synchronous computation
}, condition: () {
  // Some condition
  return true; // Execute the computation immediately
});

Implementation

FutureOr<T> asap<T>(
  T Function() computation, {
  bool Function()? condition,
}) async {
  T val;
  if (condition == null || !condition()) {
    await Future<T>.delayed(Duration.zero);
    val = computation();
  } else {
    val = computation();
  }
  return val;
}