News for hackers. Stuff that matters.
Re:Async Cancellation by lmilcin on Thursday November 11, 2021 @11:03PM (#29196203)
I have tested a lot of async frameworks in a lot of languages and I like ReactiveX for Java (RxJava, Reactor) the most.

    // process1 does nothing and takes 20s to complete
    // if cancelled, it will print a message
    private Mono<Void> process1() {
        return Mono
                .just(new Object())
                .delayElement(Duration.ofSeconds(20))
                .then()
                .doOnCancel(() -> log.info("I have just been canceled"));
    }


    // assume it does the same as process1
    private Mono<Void> process2() {
        ...
    }
    
    private Mono<Object> cancellationSignal() {
        return Mono
                .just(new Object())
                .delayElement(Duration.ofSeconds(10))
                .doOnNext(n -> log.info("oops, sending cancellation"));
    }

    // executes process1, then process2
    // if cancellationSignal happens before they finish they will be safely cancelled, you will only receive message from process1
    private Mono<Void> compositeSequential() {
        return process1()
                .then(process2())
                // timeout() is just one way to cause cancellation (in this case on an arbitrary signal)
                .timeout(cancellationSignal());
    }

    // executes both processes concurrently
    // you will receive messages from both processes as they are both getting the cancellation
    private Mono<Void> compositeConcurrent() {
        return Flux
                .just(process1(), process2())
                .flatMap(identity())
                .then()
                .timeout(cancellationSignal());
    }
Re:Async Cancellation by vips7L on Friday November 12, 2021 @07:50AM (#29198795)
Having used Rx extensively in a desktop app, I’m very looking forward to reactive programming dying. It’s done nothing but add technical debt and increase maintenance costs at this point.