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

Improve Concurrent.unicast API #13

@wsargent

Description

@wsargent

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])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions