ZipResults class

author:ZhengZaiHong email:1096877329@qq.com date:2026-06-02 11:27 describe: 通过zipRequest执行的并发请求聚合结果的容器。 Container for aggregated results from concurrent requests executed via zipRequest. ZipResults provides type-safe access to results from multiple concurrent requests, maintaining the original submission order and supporting both index-based and tag-based access.

Features

  • Order Preservation: Results are stored in the same order as requests were submitted
  • Type Safety: Generic methods ensure compile-time type checking
  • Dual Access: Access results by index or by optional tag
  • Error Handling: Distinguishes between successful and failed requests
  • Partial Success: When eagerError: false, contains both successful results and errors

Usage

final results = await RxNet.zipRequest([
  ZipRequest<UserInfo>(request: getUserAsync, tag: 'user'),
  ZipRequest<List<Product>>(request: getProductsAsync, tag: 'products'),
]);

// Access by tag with type safety
final user = results.getRequestByTag<UserInfo>('user');
final products = results.getRequestByTag<List<Product>>('products');

// Access by index
final firstResult = results.getRequestByIndex<UserInfo>(0);

// Check success status
if (results.isSuccess(0)) {
  print('First request succeeded');
}

// Get all successful results
final successful = results.successfulResults;

Error Handling

When a request fails and eagerError: false, the error is stored internally. Attempting to access a failed request's result will throw the original error:

try {
  final result = results.getRequestByIndex<UserInfo>(0);
} catch (e) {
  print('Request failed: $e');
}

// Or check before accessing
if (results.isSuccess(0)) {
  final result = results.getRequestByIndex<UserInfo>(0);
}

See also:

Constructors

ZipResults(List _results, Map<String, int> _tagIndexMap, [Map<int, dynamic> _errors = const {}])
Creates a ZipResults instance with results, tag mapping, and optional errors.

Properties

errors → Map<int, dynamic>
Returns an unmodifiable map of all errors from failed requests.
no setter
hashCode → int
The hash code for this object.
no setterinherited
length → int
Returns the total number of requests in this result set.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
successfulResults → List
Returns a list of all successful results, excluding failed requests.
no setter

Methods

getRequestByIndex<T>(int index) → T
Retrieves the result at the specified index with type safety.
getRequestByTag<T>(String tag) → T
Retrieves the result for a request identified by tag with type safety.
isSuccess(int index) → bool
Checks whether the request at the specified index succeeded.
isSuccessByTag(String tag) → bool
Checks whether the request identified by tag succeeded.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited
operator [](int index) → dynamic
Provides index-based access to results using bracket notation.