timeout function

PollStrategy timeout(
  1. Duration duration
)

Implementation

PollStrategy timeout(Duration duration) {
  final end = DateTime.now().add(duration);
  return (
    Principal canisterId,
    RequestId requestId,
    RequestStatusResponseStatus status,
  ) async {
    if (DateTime.now().isAfter(end)) {
      throw TimeoutException(
        'Request timed out after $duration:\n'
        '  Request ID: ${requestIdToHex(requestId)}\n'
        '  Request status: $status\n',
        duration,
      );
    }
  };
}