Skip to content
This repository has been archived by the owner on Aug 6, 2020. It is now read-only.

Improve Concurrent.unicast API #13

Open
wsargent opened this issue May 18, 2017 · 0 comments
Open

Improve Concurrent.unicast API #13

wsargent opened this issue May 18, 2017 · 0 comments

Comments

@wsargent
Copy link
Member

From playframework/playframework#3619

At the moment Concurrent.unicast is really hard to use. It should often be used instead of Concurrent.broadcast, but I think it's just too hard to work out. I wanted to suggest updating the docs in #3336 to use Concurrent.unicast but I couldn't write the code succinctly.

Here's the current method signature:

  def unicast[E](
    onStart: Channel[E] => Unit,
    onComplete: => Unit = (),
    onError: (String, Input[E]) => Unit = (_: String, _: Input[E]) => ())(implicit ec: ExecutionContext) = new Enumerator[E] {

What I propose:

  • Make a new Concurrent.unicast method that creates an Enumerator that can only be used once. Only being usable once will simplify the code and make things more efficient..
  • Change the signature to use Futures instead of callbacks. We can do this because we're only using the Enumerator once.
  /**
   * @param channel The Channel to push inputs down.
   * @param completion A future that will be completed when the attached
   * Iteratee is Done or completes with an Error. Will be a failure if the
   * Iterate had an error.
   */
  final case class Unicast[E](channel: Channel[E], completion: Future[Unit])

  def unicast[E]: (Enumerator, Future[Unicast])
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant