lipanski / mockito

HTTP mocking for Rust!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Async server exposes sync methods

crepererum opened this issue · comments

From an API perspective, it's super confusing that the server created w/ Server::new_async().await still exposes sync APIs (e.g. mock), esp. because calling these seems to result in an error (Cannot start a runtime from within a runtime. This happens because a function (like block_on) attempted to block the current thread while the thread is being used to drive asynchronous tasks.).

I would suggest that there is an AsyncServer type that only exposes async APIs. This way, the _async suffix can also be removed and the code is type-safe and more readable.

Server::mock (or Server::url for that matter), doesn't call the runtime so it's safe to use in both sync and async code. For everything else there is an _async counterpart which should be preferred, as you noticed. I get that it can be slightly confusing but the API is not that big right now. I don't intend to split the Server atm but I could make this more obvious in the docs or maybe even in the error message somehow.