https://kotlinlang.org logo
Title
k

karelpeeters

12/26/2017, 4:18 PM
buildSequence(::getThingBlocking).forEach { ... }
z

ziggy42

12/26/2017, 4:25 PM
mm the
while(true)
is basically the core of the application, its only purpose is to do something with
thing
and then to get another
thing
.
k

karelpeeters

12/26/2017, 4:26 PM
Well the code I just posted does exactly the same as yours.
z

ziggy42

12/26/2017, 4:27 PM
buildSequence<String>({ client.blpop("somekey", "0") })
        .forEach { job -> logger.debug { "New job received: $job" } }
I've never used coroutines before. After the first call the process dies. Why?
buildSequence<String>({
        while (true)
            client.blpop("somekey", "0").forEach { yield(it) }
    })
        .forEach { job ->
            logger.debug { "New job received: $job" }
        }
This works
k

karelpeeters

12/26/2017, 4:47 PM
Yup, forgot to put
yield
around it.
Actually
generateSequence
would be better.
z

ziggy42

12/26/2017, 4:52 PM
generateSequence { client.blpop("key", "0")[1] }.forEach { println(it) }
Wow
k

karelpeeters

12/26/2017, 4:53 PM
Nice!