Created
April 19, 2012 17:58
-
-
Save viktorklang/2422659 to your computer and use it in GitHub Desktop.
Akka Futures in the Swing Event Dispatch Thread
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
// © 2012 Viktor Klang | |
import akka.dispatch.ExecutionContext | |
import javax.swing.SwingUtilities | |
import java.util.concurrent.Executor | |
// | |
object SwingExecutionContext { | |
implicit val swingExecutionContext: ExecutionContext = ExecutionContext.fromExecutor(new Executor { | |
def execute(command: Runnable): Unit = SwingUtilities invokeLater command | |
}) | |
} | |
// Now all you need to do is to use it | |
import SwingExecutionContext._ | |
Future { | |
… | |
} | |
// Enjoy! |
Hi!
Sorry for the late reply, just saw this.
I don't think it's needed to add to scala swing since it's just like 4 lines of code :-)
Cheers,
√
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, Viktor!
I was looking exactly for something like this.
Would be so nice to have this in the standard library, now that SIP 14 is in -- is this planned / already done? Care to open a pull request for this in
scala.swing.Swing
?I would vote for this being not implicit in
scala.swing.Swing
, so one has to explicitly set it implicit. I guess this would avoid bugs.Standard library:
Either your example or even SwingWorker simulation: