when<T> static method
Execute different callbacks based on connectivity status.
Example:
await NyConnectivity.when(
online: () async => await api.fetchData(),
offline: () async => await cache.getData(),
);
Implementation
static Future<T> when<T>({
required Future<T> Function() online,
required Future<T> Function() offline,
}) async {
if (await isOnline()) {
return await online();
}
return await offline();
}