invoke method
Run the Runtime in loop and digest events that are fetched from the AWS Lambda API Interface. The events are processed sequentially and are fetched from the AWS Lambda API Interface.
If the invocation of an event was successful the function
sends the InvocationResult via _client.postInvocationResponse(result)
to the API.
If there is an error during the execution. The execption gets catched
and the error is posted via _client.postInvocationError(err)
to the API.
Implementation
void invoke() async {
do {
NextInvocation nextInvocation;
try {
// get the next invocation
nextInvocation = await _client.getNextInvocation();
// creating the new context
final context = Context.fromNextInvocation(nextInvocation);
final func = _handlers[context.handler];
if(func == null) {
throw RuntimeException('No handler with name "${context.handler}" registered in runtime!');
}
final event =
Event.fromHandler(func.type, await nextInvocation.response);
final result = await func.handler(context, event);
await _client.postInvocationResponse(result);
} on Exception catch (error, stacktrace) {
await _client.postInvocationError(
nextInvocation.requestId, InvocationError(error, stacktrace));
}
nextInvocation = null;
} while (true);
}