mirror of
https://github.com/corda/corda.git
synced 2025-05-03 17:23:03 +00:00
Merged in quasarScan-warning-fix (pull request #143)
Remove quasar scan related warnings of suspendable supers outside our project (in kotlin stdlib).
This commit is contained in:
commit
cba76bb0f4
@ -4,6 +4,7 @@ import co.paralleluniverse.fibers.Suspendable
|
|||||||
import co.paralleluniverse.strands.AbstractFuture
|
import co.paralleluniverse.strands.AbstractFuture
|
||||||
import co.paralleluniverse.strands.SettableFuture
|
import co.paralleluniverse.strands.SettableFuture
|
||||||
import co.paralleluniverse.strands.Strand
|
import co.paralleluniverse.strands.Strand
|
||||||
|
import co.paralleluniverse.strands.SuspendableRunnable
|
||||||
import com.google.common.util.concurrent.ListenableFuture
|
import com.google.common.util.concurrent.ListenableFuture
|
||||||
import com.r3corda.core.then
|
import com.r3corda.core.then
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
@ -78,8 +79,9 @@ abstract class MutableClock : Clock() {
|
|||||||
*
|
*
|
||||||
* @throws InterruptedException if interrupted by something other than a [MutableClock]
|
* @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
|
@Suspendable
|
||||||
private fun Clock.doInterruptibly(runnable: () -> Unit) {
|
private fun Clock.doInterruptibly(runnable: SuspendableRunnable) {
|
||||||
var version = 0L
|
var version = 0L
|
||||||
var subscription: Subscription? = null
|
var subscription: Subscription? = null
|
||||||
try {
|
try {
|
||||||
@ -88,7 +90,7 @@ private fun Clock.doInterruptibly(runnable: () -> Unit) {
|
|||||||
val strand = Strand.currentStrand()
|
val strand = Strand.currentStrand()
|
||||||
subscription = this.mutations.subscribe { strand.interrupt() }
|
subscription = this.mutations.subscribe { strand.interrupt() }
|
||||||
}
|
}
|
||||||
runnable()
|
runnable.run()
|
||||||
} catch(e: InterruptedException) {
|
} catch(e: InterruptedException) {
|
||||||
// If clock has not mutated, then re-throw
|
// If clock has not mutated, then re-throw
|
||||||
val newVersion = if (this is MutableClock) this.mutationCount else version
|
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
|
var nanos = 0L
|
||||||
do {
|
do {
|
||||||
doInterruptibly @Suspendable {
|
doInterruptibly(SuspendableRunnable {
|
||||||
nanos = Duration.between(this.instant(), deadline).toNanos()
|
nanos = Duration.between(this.instant(), deadline).toNanos()
|
||||||
if (nanos > 0) {
|
if (nanos > 0) {
|
||||||
try {
|
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
|
// No need to take action as will fall out of the loop due to future.isDone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
} while (!future.isDone && nanos > 0)
|
} while (!future.isDone && nanos > 0)
|
||||||
return future.isDone
|
return future.isDone
|
||||||
}
|
}
|
||||||
@ -143,11 +145,11 @@ private fun <T : Any> makeFutureCurrentStrandFriendly(future: Future<T>): Future
|
|||||||
return if (Strand.isCurrentFiber() && future !is AbstractFuture) {
|
return if (Strand.isCurrentFiber() && future !is AbstractFuture) {
|
||||||
if (future is ListenableFuture) {
|
if (future is ListenableFuture) {
|
||||||
val settable = SettableFuture<T>()
|
val settable = SettableFuture<T>()
|
||||||
future.then @Suspendable { settable.set(null) }
|
future.then { settable.set(null) }
|
||||||
settable
|
settable
|
||||||
} else if (future is CompletableFuture) {
|
} else if (future is CompletableFuture) {
|
||||||
val settable = SettableFuture<T>()
|
val settable = SettableFuture<T>()
|
||||||
future.whenComplete(BiConsumer @Suspendable { value, throwable -> settable.set(null) })
|
future.whenComplete(BiConsumer { value, throwable -> settable.set(null) })
|
||||||
settable
|
settable
|
||||||
} else {
|
} else {
|
||||||
throw IllegalArgumentException("Cannot make future $future Fiber friendly whilst on a Fiber")
|
throw IllegalArgumentException("Cannot make future $future Fiber friendly whilst on a Fiber")
|
||||||
|
@ -38,6 +38,8 @@ import kotlin.concurrent.withLock
|
|||||||
*/
|
*/
|
||||||
class FiberBox<T>(private val content: T, private val lock: Lock = ReentrantLock()) {
|
class FiberBox<T>(private val content: T, private val lock: Lock = ReentrantLock()) {
|
||||||
private var mutated: SettableFuture<Boolean>? = null
|
private var mutated: SettableFuture<Boolean>? = null
|
||||||
|
|
||||||
|
@Suppress("UNUSED_VALUE") // This is here due to the compiler thinking ourMutated is not used
|
||||||
@Suspendable
|
@Suspendable
|
||||||
fun <R> readWithDeadline(clock: Clock, deadline: Instant, body: T.() -> R): R {
|
fun <R> readWithDeadline(clock: Clock, deadline: Instant, body: T.() -> R): R {
|
||||||
var ex: Exception
|
var ex: Exception
|
||||||
|
Loading…
x
Reference in New Issue
Block a user