reject method

Future<void> reject()

Should be invoked when results of compilation are rejected by the client.

Either accept or reject should be called after every compile call.

The result of this call must be awaited before a new compile can be done.

Implementation

Future<void> reject() async {
  if (_state != _ClientState.waitingForAcceptOrReject) {
    throw StateError(
        'Called `reject` but there was no previous compile to reject.');
  }
  _state = _ClientState.rejecting;
  _sendCommand('reject');
  late String boundaryKey;
  var rejectState = _RejectState.started;
  while (rejectState != _RejectState.done &&
      await _feServerStdoutLines.hasNext) {
    var line = await _nextInputLine();
    switch (rejectState) {
      case _RejectState.started:
        if (!line.startsWith('result')) {
          throw StateError(
              'Expected a line like `result <boundary-key>` after a `reject` '
              'command, but got:\n$line');
        }
        boundaryKey = line.split(' ').last;
        rejectState = _RejectState.waitingForKey;
        continue;
      case _RejectState.waitingForKey:
        if (line != boundaryKey) {
          throw StateError('Expected exactly `$boundaryKey` but got:\n$line');
        }
        rejectState = _RejectState.done;
        continue;
      case _RejectState.done:
        throw StateError('Unreachable');
    }
  }
  _state = _ClientState.waitingForRecompile;
}