Add Promise support for http callout #265
Open
+657
−4
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.
In the current envoy WASM plugins, if we need IO request such as HTTP/GRPC/Redis, we must register request to envoy event loop and assigned a token via such as
dispatch_http_call
and WASM plugin should yield current request lifetime usingAction::Pause
. When the IO request completed, the envoy will callback to WASM plugin viaon_http_call_response
, and plugin should dispatch response using token (or ignored if single IO request). If we want to share something betweendispatch_http_call
andon_http_call_response
, we must share them in plugin context fields, it's not a suitable scope.Here is an example from proxy-wasm-rust-sdk
So there is three major problem we need to resolve:
In Rust async programming, normally we use
async/await
for IO request, but in envoy WASM plugin, there is no executor to poll future. A suitable solution is providing JavaScript style Promise (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). With Promise, we could write all logic in single functionIt seems more fluid then writing in callback of
on_http_call_response
, but there is no executor for promise to trigger state transferring. We can useon_http_call_response
as trigger simplyAs for making relationship between multi tokens and promises, we could just using
HashMap
withinsert/remove
(maybe it should be embed in SDK but not belongs to this PR)Note:
hostcalls
is re-implemented ofresume_http_request
andsend_http_response
because we cannot moveself
to callbacks.