Allows async hosts by splitting "handle" #16
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This reduces the complexity of implementing async hosts such as mosn by splitting the guest export "handle" into "handle_request" and "handle_response".
handle_request: called by the host on each request and returnsnext=1to continue to the next handler on the host.handle_response: caller by the host, regardless of error, whenhandle_requestreturnednext=1.The
nextfield is combined with an optionalreqCtxas the i64 result ofhandler_request.When the guest decides to proceed to the next handler, it can return
ctxNext=1which is the same asnext=1without any request context. If it wants the host to propagate request context, it shifts that into the upper 32-bits of ctxNext like so:Impact of the new design
This results in the same amount of calls between the guest and the host, as "next" is no longer needed. This also allows the guest to be called regardless of host failure, for example in logging interceptors. On the other hand, splitting the ABI may feel a little more work, as you have to define two callbacks, not one. That said, in TinyGo, the default response callback will be invisible to those who only deal with requests, as it can simply no-op return.
Signed-off-by: Adrian Cole [email protected]