call method

  1. @override
Future<Either<RepositoryError, Info>> call({
  1. required covariant Params repositoryParams,
})
override

Overrides the repository call to apply deduplication.

  • If a call with the same usecaseParams is already in progress, returns the existing Future.
  • Otherwise, initiates a new data source call, stores the Completer, and completes it once the operation finishes.

Implementation

@override
Future<Either<RepositoryError, Info>> call({
  required covariant Params repositoryParams,
}) async {
  final completer = _deduplication[repositoryParams];
  if (completer != null) {
    return completer.future;
  }
  _deduplication[repositoryParams] = Completer();

  final datasourceResponse = await super.call(
    repositoryParams: repositoryParams,
  );

  _deduplication[repositoryParams]?.complete(datasourceResponse);
  _deduplication.remove(repositoryParams);

  return datasourceResponse;
}