isAsync abstract method
Determines whether this method is asynchronous — i.e., declared using
the async keyword or returning a Future-like type.
Unlike isFutureVoid, which specifically checks for a Future<void>
return type, this method performs a broader inspection to determine
whether the method represents any asynchronous computation.
Typical Uses
- Dynamic invocation frameworks: to decide whether to
awaitthe result. - Proxy or interceptor implementations: to preserve correct async semantics.
- Runtime analysis tools: to distinguish between synchronous and asynchronous flows.
Example
class Example {
Future<void> save() async {}
Future<int> compute() async => 42;
void reset() {}
}
final saveMethod = Class(Example).getMethod('save');
final computeMethod = Class(Example).getMethod('compute');
final resetMethod = Class(Example).getMethod('reset');
print(saveMethod.isAsync()); // true
print(computeMethod.isAsync()); // true
print(resetMethod.isAsync()); // false
Return
true if the method is declared as asynchronous (returns a Future or
is marked with async), otherwise false.
Implementation
bool isAsync();