You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Service trait requires users to call poll_ready before invoking the call function in order to check if the service is ready or not. However, users are not obligated to do this and may forget to call poll_ready.
Therefore, it is worth considering whether it would be beneficial to use the type system to prevent users from invoking call if the service is not ready.
One suggestion is to introduce a ready token with type Service::Ready as follows:
With this approach, users must obtain a token: Self::Ready before invoking call, which can only be extracted from Poll::Ready(Ok(Self::Ready)). This follows the "Parse, not validate" paradigm.
Incorporating the ready token in the implementation of Service would help eliminate the need for checking the invalid state that may occur while invoking call:
The Service trait requires users to call
poll_ready
before invoking thecall
function in order to check if the service is ready or not. However, users are not obligated to do this and may forget to callpoll_ready
.Therefore, it is worth considering whether it would be beneficial to use the type system to prevent users from invoking
call
if the service is not ready.One suggestion is to introduce a ready token with type
Service::Ready
as follows:With this approach, users must obtain a
token: Self::Ready
before invokingcall
, which can only be extracted fromPoll::Ready(Ok(Self::Ready))
. This follows the "Parse, not validate" paradigm.Incorporating the ready token in the implementation of
Service
would help eliminate the need for checking the invalid state that may occur while invokingcall
:tower/tower/src/limit/rate/service.rs
Line 116 in 664cb35
The text was updated successfully, but these errors were encountered: