Skip to content

Instantly share code, notes, and snippets.

@nsadeh
Last active August 9, 2020 16:17
Show Gist options
  • Save nsadeh/befa2344b3d2bdd038c091cc85910ebf to your computer and use it in GitHub Desktop.
Save nsadeh/befa2344b3d2bdd038c091cc85910ebf to your computer and use it in GitHub Desktop.
implicit val spawnSystem = ActorSystem(SpawnProtocol(), "spawn")
def messageRoute =
// pattern matching on the URL
pathPrefix("message" / Segment) { trainerId =>
// await on the webflow materialization pending session actor creation by the spawnSystem
Await.ready(ChatSessionMap.findOrCreate(trainerId).webflow(), Duration.Inf).value.get match {
case Success(value) => handleWebSocketMessages(value)
case Failure(exception) =>
println(exception.getMessage())
failWith(exception)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment