From a0087c2e17e6cbf6fe1556b2b3a7b9d125f2d4b4 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 20 Dec 2017 22:32:50 +0300 Subject: [PATCH] A lot of minor fixes. Moving some code to kotlin --- numass-main/src/main/kotlin/inr/numass/data/Generator.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/numass-main/src/main/kotlin/inr/numass/data/Generator.kt b/numass-main/src/main/kotlin/inr/numass/data/Generator.kt index 6c71bc12..16b9e3cb 100644 --- a/numass-main/src/main/kotlin/inr/numass/data/Generator.kt +++ b/numass-main/src/main/kotlin/inr/numass/data/Generator.kt @@ -6,6 +6,9 @@ import hep.dataforge.maths.chain.StatefulChain import inr.numass.data.api.NumassBlock import inr.numass.data.api.NumassEvent import inr.numass.data.api.SimpleBlock +import kotlinx.coroutines.experimental.channels.takeWhile +import kotlinx.coroutines.experimental.channels.toList +import kotlinx.coroutines.experimental.runBlocking import org.apache.commons.math3.random.JDKRandomGenerator import org.apache.commons.math3.random.RandomGenerator import java.time.Duration @@ -20,7 +23,8 @@ private fun RandomGenerator.nextDeltaTime(cr: Double): Long { } fun generateBlock(start: Instant, length: Long, chain: Chain): NumassBlock { - val events = chain.asSequence().takeWhile { it.timeOffset < length }.toList() + + val events = runBlocking { chain.asChannel().takeWhile { it.timeOffset < length }.toList()} return SimpleBlock(start, Duration.ofNanos(length), events) }