blob: e7c05beb65780a775c97302f120d74324409dd6c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package scala.tools.nsc
package util
/** A class of work items to be used in interrupt requests.
*/
abstract class InterruptReq {
/** The result type of the operation
*/
type R
/** The operation to be performed */
protected val todo: () => R
/** The result provided */
private var result: Option[Either[R, Throwable]] = None
/** To be called from interrupted server to execute demanded task */
def execute(): Unit = synchronized {
try {
result = Some(Left(todo()))
} catch {
case t => result = Some(Right(t))
}
notify()
}
/** To be called from interrupting client to get result fo interrupt */
def getResult(): R = synchronized {
while (result.isEmpty) wait()
result.get match {
case Left(res) => res
case Right(t) => throw t
}
}
}
|