diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/util/InterruptReq.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/util/InterruptReq.scala | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/util/InterruptReq.scala b/src/compiler/scala/tools/nsc/util/InterruptReq.scala new file mode 100644 index 0000000000..aa7804acbe --- /dev/null +++ b/src/compiler/scala/tools/nsc/util/InterruptReq.scala @@ -0,0 +1,28 @@ +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[R] = None + + /** To be called from interrupted server to execute demanded task */ + def execute(): Unit = synchronized { + result = Some(todo()) + notify() + } + + /** To be called from interrupting client to get result fo interrupt */ + def getResult(): R = synchronized { + while (result.isEmpty) wait() + result.get + } +} |