I have api that gets such request:
case class UsersRequest(ids: List[Long])
and returns such response:
case class UsersInfoResponse(info: List[Info])
case class Info(userId: Long, info: String)
also, i have methods that send this request and create user:
def createUser(id: Long): IO[Throwable, User] = {
getUserInfo(id)
.map(info => User(id, info))
}
def getUserInfo(id:Long): IO[Throwable, String] = {
here i call grpc service
service.getUserInfo(UsersRequest(List(id)))
}
I want:
- write ZStream that create ids batch
- every 1 sec takes 10 ids and creates UsersRequest
- gets UsersInfoResponse
- using id understands what info must gets
- return info
So that I can do it i should create something similar:
def getUserInfo(id:Long): IO[Throwable, String] = {
Stream
.fromQueue()
.groupedWithin(10, Duration.Zero)
.????
.runDrain
.forkManaged
AND
p <- Promise.make[Throwable, String]
interrupted <- Promise.make[Nothing, Unit]
env <- ZIO.environment[R]
}
I don't how i can do it. How can build batch and send the request and after match by id get result?