fetch method

Future<Map<String, dynamic>> fetch(
  1. String id
)

Fetch task result by ID

Implementation

Future<Map<String, dynamic>> fetch(String id) async {
  final endpoint = '$baseUrl/fetch/$id';
  Map<String, dynamic>? response;

  for (int i = 0; i < client.fetchRetry; i++) {
    response = await _post(
      endpoint,
      data: {'key': client.key},
    );

    if (response['status'] == 'success') {
      break;
    } else {
      await Future.delayed(Duration(seconds: client.fetchTimeout));
    }
  }

  if (response == null) {
    throw Exception('Failed to fetch task response.');
  }

  return response;
}