Hacker News new | past | comments | ask | show | jobs | submit login

One of the things I've come to appreciate about Reactive Streams is the ability to catch a cancel event and handle it appropriately in your stream. A cancel event can be a timeout or a manual disposal of your async process, but whatever the case you are given the opportunity to deal with it.

    fun doLongRunning(): Single<Result> {
        return Single.create { emitter ->
            val longProcess = /* whatever */
            emitter.onSuccess(longProcess_result)
            emitter.setCancellable {
                cleanup(longProcess)
            }
        }
    }

    doLongRunning()
    .timeout(5_secs)
    .subscribe({ result ->

    }, { error ->
    
    })



What language is this? It looks like some sort of Java/JVM.


Probably RxJava https://github.com/ReactiveX/RxJava (with Kotlin?)


That's kotlin




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: