-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A PoC of Gears integration #2142
Conversation
@odersky @natsukagami Before releasing sttp-client4, it would be great to determine if there's something in the library itself that needs to be changed to provide support for a future Gears release (it will be much harder once the release is done). I think one of the basic questions is when we have a hypothetical val response: Response[...] = myRequest.send(gearsBackend) // Async must be in scope, `send` has a Async ?=> type Where the request is sent at the point of invocation. Or, we can have the lazy version: val response: Async ?=> Response[...] = myRequest.send(gearsBackend) where we defer effects. I'm quite sure that the first version is what we want, but better to double-check :) The second question is how a gears backend would look like. In the PoC I have it captured simply as a Well, if you have any thoughts, let me know :) |
Hi! I definitely prefer the first variant, and I suppose the second variant is also pretty hard to use? (as in it's not that easy to keep the laziness) As for the backend, my (also really hacky) PoCs all used the |
@natsukagami Ah, great to hear you did some tests as well :) So if we just have a backend of type |
I think that's what you want most of the time. Either |
I guess the question is, if you have a On the other hand, having both:
methods on the |
This does iirc
will give you a compiler error with "ambiguous overload" at call site I think. |
Yeah just checked, works fine. I guess I'll close this then, always nice to have one less item on the todo list ;) |
See https://github.com/lampepfl/gears
Currently sttp-client defines a couple of backend types:
SyncBackend
,Backend[F[_]]
,WebSocketSyncBackend
,StreamBackend[F[_], +S]
,WebSocketStreamBackend[F[_], S]
.They all inherit from a
GenericBackend[F[_], +P]
(where P are supported sttp-capabilities, such as streaming and websockets), but sttp has specialisied "concrete" types for better auto-complete and general developer experience.My first first thought was to add a
CapabilityBackend[C]
to the hierarchy, but this would mean also adding a WebSocket/Streaming variants, and adding the new variants for all generic backend wrappers. This would additionally complicate the already complicated setup.So instead, I went with representing the "Gears effect" as a type constructor (I called it
Deferred
), and usingBackend[F[_]]
:One thing that is not ideal is the
.send
variant that I had to add, which would work for any capability:This is needed so that both of these compile:
(without it only the second, not-explicitly-typed one compiles)
I also tried adding a gears-specific extension method (which would have a
using Async
, instead of the generic formulation above), but unfortunately the.send
methods defined directly in theRequest
class have priority, so this method was never taken into consideration.Anyway, summing up, to add gears integration into sttp-client with the approach above, we have to:
.send
variant