Skip to content

Instantly share code, notes, and snippets.

@d108
Created June 10, 2019 02:40
Show Gist options
  • Save d108/e41cd98c75bbb0bc37c508260b09f3e1 to your computer and use it in GitHub Desktop.
Save d108/e41cd98c75bbb0bc37c508260b09f3e1 to your computer and use it in GitHub Desktop.
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