playframework / playframework/play-socket.io

Possible for namespace methods to return Futures of flows?

Open
#11 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
96
Forks
33
PR merge metrics
No merged PRs in 30d

Description

Hi,

I find myself sometimes asking another Actor to produce a Flow for me. For instance, this is used heavily in this example: https://github.com/playframework/play-scala-websocket-example (native websockets). In this case, the method requires you to return a Future[Flow]:

  /**
   * Creates an action that will either accept the websocket, using the given flow to handle the in and out stream, or
   * return a result to reject the Websocket.
   */
  def acceptOrResult[In, Out](f: RequestHeader => Future[Either[Result, Flow[In, Out, _]]])(implicit transformer: MessageFlowTransformer[In, Out]): WebSocket = {
    WebSocket { request =>
      f(request).map(_.right.map(transformer.transform))
    }
  }

Is it possible to use a similar pattern in this library or is it not relevant?

My other question is that is it possible to do some clean up actions? Something like onDisconnect?

Thanks for this library!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the library's namespace methods and compare their return patterns with the Play example's acceptOrResult method, which returns a Future[Either[Result, Flow]]. Also inspect the existing lifecycle API for any onDisconnect-style cleanup support. Done means documenting or agreeing on the supported behavior for asynchronous Flow creation and disconnect cleanup.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.