Tonic Async Interceptor
This crate contains AsyncInterceptor
, an async variant of Tonic's
Interceptor
.
Other than accepting an async interceptor function, it works the same as Interceptor
.
Async interceptor functions are useful for tasks like authentication, where you need to make asynchronous calls to another service or database within the interceptor.
Usage
Using with Tonic built-in Server/Router
async
async
Setting a custom extension
Here's an example of an async interceptor which authenticates a user and sets a custom extension for the underlying service to use.
// Your custom extension
// Async interceptor fn
async
Why is this a separate crate?
The code in this crate was originally intended to live in the official Tonic crate, alongside the non-async interceptor code. However, the maintainer decided not to merge it due to lack of time and misalignment with his future vision for Tonic.