Last active
August 29, 2015 14:03
-
-
Save stanch/26804564fefa6b154f42 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@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