Skip to content

Commit

Permalink
Examples - using countdown latch on ZPong
Browse files Browse the repository at this point in the history
  • Loading branch information
DariusIMP committed Nov 29, 2024
1 parent 82f86f1 commit db637e6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions examples/src/main/kotlin/io.zenoh/ZPong.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ import io.zenoh.keyexpr.intoKeyExpr
import io.zenoh.qos.CongestionControl
import io.zenoh.qos.QoS
import io.zenoh.sample.Sample
import java.util.concurrent.CountDownLatch

class ZPong(private val emptyArgs: Boolean) : CliktCommand(
help = "Zenoh ZPong example"
) {
val latch = CountDownLatch(1)

override fun run() {
val config = loadConfig(emptyArgs, configFile, connect, listen, noMulticastScouting, mode)

Expand All @@ -37,7 +40,7 @@ class ZPong(private val emptyArgs: Boolean) : CliktCommand(
val publisher = session.declarePublisher(keyExprPong, qos = QoS(CongestionControl.BLOCK, express = !noExpress)).getOrThrow()
session.declareSubscriber(keyExprPing, callback = { sample: Sample -> publisher.put(sample.payload).getOrThrow() }).getOrThrow()

while (true) { Thread.sleep(1000)}
latch.await()
}


Expand All @@ -63,4 +66,7 @@ class ZPong(private val emptyArgs: Boolean) : CliktCommand(
).flag(default = false)
}

fun main(args: Array<String>) = ZPong(args.isEmpty()).main(args)
fun main(args: Array<String>) {
val zPong = ZPong(args.isEmpty())
zPong.main(args)
}

0 comments on commit db637e6

Please sign in to comment.