Skip to content

Instantly share code, notes, and snippets.

@tuhlmann
Created March 23, 2013 13:27
Show Gist options
  • Save tuhlmann/5227734 to your computer and use it in GitHub Desktop.
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.
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