harryh RSS

I don't really like tumblr much, but all my friends seem to use it so I'm kinda stuck. I miss the era of LiveJournal.

Archive

Feb
24th
Wed
permalink

trival backgrounding with scala actors

A simple backgrounding object:

object BackgroundOperation {
   def apply(f: => Unit) = {
     BackgroundActor ! BackgroundJob(() => f)
   }

   case class BackgroundJob(f: () => Unit)
   
   object BackgroundActor extends LiftActor {
     protected def messageHandler = {
       case BackgroundJob(f) => f()
     }
  }
}

Then you can do this whenever you want:

BackgroundOperation {
  // some complicated thing
}