Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

room.websocket returning a WebSocket object #1

Open
atamborrino opened this issue Oct 14, 2013 · 5 comments
Open

room.websocket returning a WebSocket object #1

atamborrino opened this issue Oct 14, 2013 · 5 comments

Comments

@atamborrino
Copy link

As room.websocket directly returns a WebSocket object, how can you deal with a futureRoom in your controller?

For example I want to keep a Map roomId -> room in an actor. In my controller, I want to retrieve a room according to its id:

def websocket(roomId: String) = {
  val futureRoom = // ask the actor the room of id = roomId
  val futureWebsocket: Future[WebSocket] = futureRoom.map(_.websocket(...))
  ???
}

Should we instead make room.websocket return a tuple (Iteratee, Enumerator), so that in this case we get a Future[(Iteratee, Enumerator)] which can be flattened or used with Websocket.async ?

def websocket(roomId: String) = WebSocket.async {
  val futureRoom = // ask the actor the room of id = roomId
  futureRoom.map(_.websocket(...))
}
@mandubian
Copy link
Owner

I see...
Actually I wanted to hide completely iteratee/enumerator since I think people shouldn't care about it... too low level and complex for most users...

What about providing a Room.async to hide it?
def websocket(roomId: String) = Room.async {
val futureRoom = // ask the actor the room of id = roomId
futureRoom.map(_.websocket(...))
}
it would hide the flattening of enumerator/iteratee...
Not so nice but still keeping iteratee/enumerator out of sight...

WDYT?

@atamborrino
Copy link
Author

What type would return room.websocket in that case? If it returns (Iteratee, Enumerator), Room.async will do the same job as WebSocket.async, right?

@mandubian
Copy link
Owner

No I'd like to keep WebSocket as the return type...
Room.async will flatten a Future[WebSocket] into WebSocket as Iteratee.flatten...
Room.flattenWebSocket if you prefer...

Something like:

object Room {

  def async[A]( fws: => Future[WebSocket[A]] )(implicit frameFormatter: WebSocket.FrameFormatter[A]) = {
    WebSocket[A](h => (e, i) => {
      fws onSuccess { case ws => ws.f(h)(e, i) }
    })
  }

}

@atamborrino
Copy link
Author

Oh ok I see, I didn't realize it was possible to do that.
So yes, a Room.async like you suggested would be very useful ;)

@mandubian
Copy link
Owner

I wondered too but it is possible :D
I should try to add that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants