asap<T> method
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 =>
switch (condition) {
null =>
await Future<T>.delayed(Duration.zero).then((_) => computation()),
var cond when !cond() =>
await Future<T>.delayed(Duration.zero).then((_) => computation()),
_ => computation()
};