Allowing async functions for loadbalancer/picker
- Dominant language
- TypeScript
- Stars
- 4.8k
- Forks
- 716
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 10
Description
### Problem
I'm writing a customized loadbalancer and picker (implementing `grpc.experimental.Picker` and `grpc.experimental.LoadBalancer`). In my implementation, the loadbalancer is meant to get load status from a remote endpoint, and picker would always check the remote endpoint to see if the subchannel is in "disabled" state.
For example, in `Picker.pick`, to get information from my remote endpoint, I need to call the function like this:
```js
const disabled = await remoteClient.GetIfEndpointIsolated(host, port, pickArgs.metadata.get("uid"))
```
Currently, `LoadBalancer.updateAddressList` and `Picker.pick` are all sync functions, and not accepting a `Promise<>`. Also, the return value can not be set via a callback. This makes it impossible to call the remote endpoint in those two functions.
However, the same way of checking information from remote endpoint works well for the Golang and C++ version since in those languages `Promise` works in a different way.
### Possible solution
Add `async` to `LoadBalancer.updateAddressList` and `Picker.pick` like this:
```
...
async pick(pickArgs: PickArgs): Promise;
...
```
Or add `pickAsync` as an alternative.
I had thought if callback is acceptable, but I think it would make no differences than using `await`.
### Possible Problems
It might not be a wise idea to make `Pick` and `Loadbalancer` costing too much time, considering they are frequently called. However, allowing `Promise` here does not mean users have to call remote (they can still write a simple picker and choose subchannel without external information`. Additionally, considering customizing those two objects are in *experimental* state and if you are writing code for them, you should have considerable knowledge of how gRPC call works, users should make their own responsibility if they take the risk to call remote endpoint for additional information for picking.
Contributor guide
Assessment
This issue has not been assessed yet.