From a76b39260953ba07d09e35181706c9fd94ee0cbe Mon Sep 17 00:00:00 2001 From: Joseph Shraibman Date: Tue, 29 Nov 2011 20:41:00 -0500 Subject: [PATCH] Use callback with future, instead of blocking and replying in original thread --- src/main/scala/collaboration.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/scala/collaboration.scala b/src/main/scala/collaboration.scala index a0dd70e..f118fb0 100644 --- a/src/main/scala/collaboration.scala +++ b/src/main/scala/collaboration.scala @@ -22,9 +22,12 @@ class CollaborationPlan(drawings: DrawingStore, drawingActor: Actor) case GET(Path(Seg("drawing" :: id :: Nil))) => { case Open(s) => sockets += id -> (sockets(id) + s) - (drawingActor !! FetchDrawing(id))() match { - case rawSvg: String => s.send(rawSvg) - } + (drawingActor !! FetchDrawing(id)) foreach( x => x match { + //I'm not sure in what thread this callback is executed in, + //so to be safe do the s.send in another thread + case rawSvg: String => scala.actors.Actor.actor { s.send(rawSvg) } + case y => System.err.println("ERROR expected string, got: "+y) + }) case Message(s, Text(msg)) => /* Message downstream clients with the new stroke and update the shared drawing. */