requestNextBenchmark method

Future<String> requestNextBenchmark()

Asks the local server for the name of the next benchmark to run.

Returns kManualFallback if local server is not available (uses 404 as a signal).

Implementation

Future<String> requestNextBenchmark() async {
  final XMLHttpRequest request = await _requestXhr(
    '/next-benchmark',
    method: 'POST',
    mimeType: 'application/json',
    sendData: json.encode(_benchmarks.keys.toList()),
  );

  // `kEndOfBenchmarks` is expected when the benchmark server is telling us there are no more benchmarks to run.
  // 404 is expected when the benchmark is run using plain `flutter run`, which does not provide "next-benchmark" handler.
  if (request.responseText == kEndOfBenchmarks || request.status == 404) {
    isInManualMode = true;
    return kManualFallback;
  }

  isInManualMode = false;
  return request.responseText;
}