|
Scala example source code file (InterruptReq.scala)
The Scala InterruptReq.scala source codepackage 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 for interrupt */ def getResult(): R = synchronized { while (result.isEmpty) { try { wait() } catch { case _ : InterruptedException => () } } result.get match { case Left(res) => res case Right(t) => throw new FailedInterrupt(t) } } } class FailedInterrupt(cause: Throwable) extends Exception("Compiler exception during call to 'ask'", cause) Other Scala examples (source code examples)Here is a short list of links related to this Scala InterruptReq.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.