run method
Future<List<APIResponse> >
run(
- FutureOr<
String?> nextLine(), { - bool returnResponses = true,
- dynamic onRequest(
- APIRequest request
- dynamic onResponse(
- APIResponse response
Runs the console interaction.
Implementation
Future<List<APIResponse>> run(
FutureOr<String?> Function() nextLine, {
bool returnResponses = true,
Function(APIRequest request)? onRequest,
Function(APIResponse response)? onResponse,
}) async {
var responses = <APIResponse>[];
while (true) {
var ret = nextLine();
String? line;
if (ret is Future) {
line = await ret;
} else {
line = ret;
}
if (line == null) {
return responses;
}
var request = APIRequest.fromArgsLine(line);
if (onRequest != null) {
var ret = onRequest(request);
if (ret is Future) {
ret = await ret;
}
if (ret is APIRequest) {
request = ret;
}
}
var response = await processRequest(request);
if (returnResponses) {
responses.add(response);
}
if (onResponse != null) {
var ret = onResponse(response);
if (ret is Future) {
await ret;
}
}
}
}