Created
June 10, 2019 02:40
-
-
Save d108/e41cd98c75bbb0bc37c508260b09f3e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun waitForCount() = runBlocking { | |
val count = async { | |
parseDaily() | |
} | |
count.await() | |
} | |
suspend fun parseDaily(): Int | |
{ | |
val dataKey = "Time Series (Daily)" | |
val klx = Klaxon() | |
val f = File(pathname).readText() | |
val parsed = klx.parseJsonObject(StringReader(f)) | |
val timeSeries = parsed.filter { | |
it.key == dataKey | |
}.map { | |
it.value as JsonObject | |
} | |
var days = ArrayList<Daily?>() | |
timeSeries.first().values.forEach { | |
val rslt = klx.parseFromJsonObject<Daily>(it as JsonObject) | |
days.add(rslt) | |
} | |
return days.size | |
} | |
@Test fun testAsyncDailyCount() | |
{ | |
val result = waitForCount() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment