From b595b23ed7af34fc9b938134fd18eded53dafbdb Mon Sep 17 00:00:00 2001 From: "rick.parker" Date: Tue, 14 Jun 2016 16:35:13 +0100 Subject: [PATCH] Remove quasar scan related warnings of suspendable supers outside our project (in kotlin stdlib). Suppressed two compiler warnings related to unused variables (seems to be compiler bug) --- .../com/r3corda/node/utilities/ClockUtils.kt | 14 ++++++++------ .../kotlin/com/r3corda/node/utilities/FiberBox.kt | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/node/src/main/kotlin/com/r3corda/node/utilities/ClockUtils.kt b/node/src/main/kotlin/com/r3corda/node/utilities/ClockUtils.kt index 42e57d2dae..051267f82e 100644 --- a/node/src/main/kotlin/com/r3corda/node/utilities/ClockUtils.kt +++ b/node/src/main/kotlin/com/r3corda/node/utilities/ClockUtils.kt @@ -4,6 +4,7 @@ import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.strands.AbstractFuture import co.paralleluniverse.strands.SettableFuture import co.paralleluniverse.strands.Strand +import co.paralleluniverse.strands.SuspendableRunnable import com.google.common.util.concurrent.ListenableFuture import com.r3corda.core.then import rx.Observable @@ -78,8 +79,9 @@ abstract class MutableClock : Clock() { * * @throws InterruptedException if interrupted by something other than a [MutableClock] */ +@Suppress("UNUSED_VALUE") // This is here due to the compiler thinking version is not used @Suspendable -private fun Clock.doInterruptibly(runnable: () -> Unit) { +private fun Clock.doInterruptibly(runnable: SuspendableRunnable) { var version = 0L var subscription: Subscription? = null try { @@ -88,7 +90,7 @@ private fun Clock.doInterruptibly(runnable: () -> Unit) { val strand = Strand.currentStrand() subscription = this.mutations.subscribe { strand.interrupt() } } - runnable() + runnable.run() } catch(e: InterruptedException) { // If clock has not mutated, then re-throw val newVersion = if (this is MutableClock) this.mutationCount else version @@ -116,7 +118,7 @@ fun Clock.awaitWithDeadline(deadline: Instant, future: Future<*> = SettableFutur var nanos = 0L do { - doInterruptibly @Suspendable { + doInterruptibly(SuspendableRunnable { nanos = Duration.between(this.instant(), deadline).toNanos() if (nanos > 0) { try { @@ -127,7 +129,7 @@ fun Clock.awaitWithDeadline(deadline: Instant, future: Future<*> = SettableFutur // No need to take action as will fall out of the loop due to future.isDone } } - } + }) } while (!future.isDone && nanos > 0) return future.isDone } @@ -143,11 +145,11 @@ private fun makeFutureCurrentStrandFriendly(future: Future): Future return if (Strand.isCurrentFiber() && future !is AbstractFuture) { if (future is ListenableFuture) { val settable = SettableFuture() - future.then @Suspendable { settable.set(null) } + future.then { settable.set(null) } settable } else if (future is CompletableFuture) { val settable = SettableFuture() - future.whenComplete(BiConsumer @Suspendable { value, throwable -> settable.set(null) }) + future.whenComplete(BiConsumer { value, throwable -> settable.set(null) }) settable } else { throw IllegalArgumentException("Cannot make future $future Fiber friendly whilst on a Fiber") diff --git a/node/src/main/kotlin/com/r3corda/node/utilities/FiberBox.kt b/node/src/main/kotlin/com/r3corda/node/utilities/FiberBox.kt index 4b712a8fb5..eddd7e8f26 100644 --- a/node/src/main/kotlin/com/r3corda/node/utilities/FiberBox.kt +++ b/node/src/main/kotlin/com/r3corda/node/utilities/FiberBox.kt @@ -38,6 +38,8 @@ import kotlin.concurrent.withLock */ class FiberBox(private val content: T, private val lock: Lock = ReentrantLock()) { private var mutated: SettableFuture? = null + + @Suppress("UNUSED_VALUE") // This is here due to the compiler thinking ourMutated is not used @Suspendable fun readWithDeadline(clock: Clock, deadline: Instant, body: T.() -> R): R { var ex: Exception