parseAsync<O> function

Sink<String> parseAsync<O>(
  1. AsyncResult<O> parse(
    1. State<ChunkedParsingSink> state
    ),
  2. void onComplete(
    1. ParseResult<ChunkedParsingSink, O> result
    )
)

Implementation

Sink<String> parseAsync<O>(
    AsyncResult<O> Function(State<ChunkedParsingSink> state) parse,
    void Function(ParseResult<ChunkedParsingSink, O> result) onComplete) {
  final input = ChunkedParsingSink();
  final state = State(input);
  final result = parse(state);
  void complete() {
    final parseResult =
        _createParseResult<ChunkedParsingSink, O>(state, result.value);
    onComplete(parseResult);
  }

  if (result.isComplete) {
    complete();
  } else {
    result.onComplete = complete;
  }

  return input;
}