Rainer Schlonvoigt
class Peripheral {} class PeripheralFinder { interface Listener { fun onPeripheralFound(peripheral: Peripheral) fun onError(error: Throwable) } fun findPeripheral(listener: Listener) {} } suspend fun findPeripheralAsync(): Peripheral { val peripheralFinder = PeripheralFinder() return withTimeout(5_000) { suspendCancellableCoroutine { continuation -> peripheralFinder.findPeripheral(listener = object : PeripheralFinder.Listener { override fun onPeripheralFound(peripheral: Peripheral) { continuation.resume(peripheral) } override fun onError(error: Throwable) { continuation.resumeWithException(error) } }) } } }
A modern programming language that makes developers happier.