timeout function

PollStrategy timeout(
  1. int timeInMsec
)

Implementation

PollStrategy timeout(int timeInMsec) {
  final end = DateTime.now().millisecondsSinceEpoch + timeInMsec;
  return (
    Principal canisterId,
    RequestId requestId,
    String status,
  ) async {
    if (DateTime.now().millisecondsSinceEpoch > end) {
      // ignore: prefer_adjacent_string_concatenation
      throw "Request timed out after $timeInMsec msec:\n"
              // ignore: prefer_adjacent_string_concatenation
              "  Request ID: ${requestIdToHex(requestId)}\n" +
          "  Request status: $status\n";
    }
  };
}