You could probably do something like that, but there is nothing that does
it out of the box. It would not really need to be blocking either,
it could be modeled as a Source that only emits resource instance handles
when they are available.

The problem then becomes to signal being done with a resource, one way
would be to design that as a Flow[ResourceHandle, ResourceHandle] where the
in-flow is return of used resource handles and the outflow is the actual
source. Another would be to signal being done with the resource using some
method on the resource handle, I think that may be the easiest and cleanest
(something like the design of the commit signalling recently done in
reactive-kafka).

Usage could look something like this:

val resourcePool: Source[ResourceHandle, NotUsed] = ???
val indata: Source[Data, NotUsed] = ???

val results: Source[ProcessingResult, NotUsed] =
  indata.zip(resourcePool).map { case (data, resourceHandle) =>
    try {
      process(data, resourceHandle.resource)
    } finally {
      resourceHandle.imDoneWithYou()
    }
  }


Implementing it would probably be a bit harder than your regular streams
usage since you need to ensure thread safety while keeping track of
resources etc. but nothing super complicated IMO.

--
Johan Andrén
Akka Team, Lightbend Inc.

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to