Skip to content

Instantly share code, notes, and snippets.

@stanch
Last active August 29, 2015 14:03
Show Gist options
  • Save stanch/26804564fefa6b154f42 to your computer and use it in GitHub Desktop.
Save stanch/26804564fefa6b154f42 to your computer and use it in GitHub Desktop.
@active
class A {
// all non-@active locals
// will be made private
var y = 0
def bar(x: Int) = x + 5
@active // should return Unit
def foo(x: Int) = {
y = bar(x)
}
}
// -------- ↓ --------
class A {
private val executor$ = Executors.newFixedThreadPool(1)
private var y = 0
private def bar(x: Int) = x + 5
def foo(x: Int) = {
executor$.submit(new Runnable {
def run = {
y = bar(x)
}
}
()
}
}
// -------- or --------
trait ActiveObject {
private lazy val executor = Executors.newFixedThreadPool(1)
def active(code: ⇒ Unit) = {
executor.submit(new Runnable { def run() = code })
()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment