isAsync static method
Determines whether the given object represents or is assignable to a
Dart Future or FutureOr type within Jetleaf’s reflective runtime.
This method provides a unified way to test for asynchronous types across both reflective Class metadata and runtime instances. It is commonly used within Jetleaf’s task scheduling, dependency injection, and asynchronous pipeline orchestration subsystems to determine whether a method or result type requires asynchronous handling.
Behavior
- If
objectis a Class, it checks assignability against both Future and FutureOr. - If
objectis an instance, it retrieves the reflective class fromobject.getClass()and reuses the same check recursively.
Example
final asyncClass = Class<Future>(null, PackageNames.DART);
final result = ClassUtils.isAsync(asyncClass);
print(result); // true
Usage in Jetleaf
This method allows Jetleaf to:
- Detect asynchronous method return types during runtime analysis.
- Manage async tasks in lifecycle methods and scheduling components.
- Correctly unwrap
FutureOr<T>in reactive pipelines.
Returns
true if the provided object (or its reflective class) represents
Future or FutureOr; otherwise, false.
See also
Implementation
static bool isAsync(Object object) {
_ensureInitialized();
if (object is Class) {
return Class<Future>().isAssignableFrom(object) || Class<FutureOr>(null, PackageNames.DART).isAssignableFrom(object);
}
final clazz = object.getClass();
return isAsync(clazz);
}