Created
March 23, 2013 13:27
-
-
Save tuhlmann/5227734 to your computer and use it in GitHub Desktop.
An example that shows a rescheduling comet that calculates stuff in the background and then causes a reRender after its ready.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SchedulingComet extends CometActor { | |
case class ContentReady(html: RenderOut) | |
case class Refresh() | |
val waitTime = 10 minutes | |
private var laContent = new LAFuture[ContentReady] | |
override def localSetup() { | |
recalculate | |
} | |
override def render = { | |
if (laContent.isSatisfied) { | |
val html = laContent.get.html | |
scheduleRefresh | |
html | |
} else ClearNodes | |
} | |
private def recalculate = { | |
laContent = calcTotal | |
laContent.foreach(this ! _) | |
} | |
private def calcTotal(): LAFuture[ContentReady] = { | |
val ret = new LAFuture[ContentReady] | |
Schedule(()=> { | |
// Do some long running calculations | |
ret.satisfy(ContentReady(renderContent(...))) | |
} | |
}) | |
ret | |
} | |
private def renderContent(...) = { | |
// My Render CssSel | |
} | |
private def scheduleRefresh = { | |
Schedule.schedule(() => this ! Refresh, waitTime) | |
} | |
override def lowPriority = { | |
case c: ContentReady => reRender | |
case Refresh() => recalculate | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment