I've hacked together something to implement the improved async support that I laid out in #916. The code could certainly be made a little bit prettier here and there, but the primary aim here is to try out the idea and see if you consider this a viable way forward.
The essential changes are:
change from requests.offer(…stuff…) *> promise.await to requests.offer(…stuff…).as(promise.await)), which makes it possible to continue processing as soon as the request was placed in the queue (SingleNodeExecutor.scala:35)
add a type parameter to the Redis trait to indicate whether it will return UIO[IO[RedisError, A]] or IO[RedisError, A] (Redis.scala:23)
change Redis.singleNode and Redis.local to provide both a synchronous and an asynchronous implementation of the Redis client (Redis.scala:45)
The resources like Queues and the Redis connection are shared between the synchronous and asynchronous Redis client, see the changes in SingleNodeExecutor.
The biggest drawback right now is that I haven't yet looked into the cluster support, so the cluster ZLayer doesn't give you an AsyncRedis object. I'd like to get some feedback on the general approach first before tackling that.
Resolves #916
Hey @mijicd,
I've hacked together something to implement the improved async support that I laid out in #916. The code could certainly be made a little bit prettier here and there, but the primary aim here is to try out the idea and see if you consider this a viable way forward.
The essential changes are:
requests.offer(…stuff…) *> promise.await
torequests.offer(…stuff…).as(promise.await))
, which makes it possible to continue processing as soon as the request was placed in the queue (SingleNodeExecutor.scala:35)Redis
trait to indicate whether it will returnUIO[IO[RedisError, A]]
orIO[RedisError, A]
(Redis.scala:23)Redis.singleNode
andRedis.local
to provide both a synchronous and an asynchronous implementation of the Redis client (Redis.scala:45)The resources like Queues and the Redis connection are shared between the synchronous and asynchronous Redis client, see the changes in
SingleNodeExecutor
.The biggest drawback right now is that I haven't yet looked into the cluster support, so the
cluster
ZLayer doesn't give you anAsyncRedis
object. I'd like to get some feedback on the general approach first before tackling that.