Q:

timeout method can't break executing in Completable.fromAction()

I discovered an error with method .timeout() in Completable, created by method .fromAction():
    Completable.fromAction(() -> {
        System.out.println("start time: " + timeString());
        Thread.sleep(10_000);
    })
            .timeout(3, TimeUnit.SECONDS)
            .onErrorComplete()
            .blockingAwait();

    System.out.println("after time: " + timeString());

Code inside the brackets executes 10 seconds, timeout set on 3 seconds. However, executing finishes only after 10 seconds. This is output of program:
start time: 14:55
after time: 15:05

Process finished with exit code 0

Question: why executing breaks not after 3 seconds and how to fix it?

A:

Try subscribeOn(Schedulers.io()) after fromAction. timeout can't interrupt the main thread but it can interrupt tasks running on a Scheduler.

