run<T> method

Future<T> run<T>(
  1. Future<T> operation(
    1. DartStreamClient client,
    2. DartStreamSession session
    )
)

Call before each operation for automatic renewal. Mutations are never automatically replayed after an ambiguous failure.

Implementation

Future<T> run<T>(
  Future<T> Function(DartStreamClient client, DartStreamSession session)
  operation,
) async {
  final current = await session();
  try {
    return await operation(client, current);
  } on DartStreamApiException catch (e) {
    if (e.statusCode == 401) {
      _session = null;
      _renewAt = null;
    }
    rethrow;
  }
}