Examples of Quasar in Kotlin (#7045)

This commit is contained in:
Graham Cox
2019-05-31 09:09:26 +01:00
committed by Grzegorz Piwowarek
parent 823cd0b9b9
commit 76370b794f
7 changed files with 477 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package com.baeldung.quasar
import co.paralleluniverse.strands.dataflow.Val
import co.paralleluniverse.strands.dataflow.Var
import org.junit.Assert
import org.junit.Test
import java.util.concurrent.TimeUnit
class DataflowTest {
@Test
fun testValVar() {
val a = Var<Int>()
val b = Val<Int>()
val c = Var<Int> { a.get() + b.get() }
val d = Var<Int> { a.get() * b.get() }
// (a*b) - (a+b)
val initialResult = Val<Int> { d.get() - c.get() }
val currentResult = Var<Int> { d.get() - c.get() }
a.set(2)
b.set(4)
Assert.assertEquals(2, initialResult.get())
Assert.assertEquals(2, currentResult.get())
a.set(3)
TimeUnit.SECONDS.sleep(1)
Assert.assertEquals(2, initialResult.get())
Assert.assertEquals(5, currentResult.get())
}
}