Skip to content

Is delaySubscription() interrupts the thread immediately as expected? #5203

@hkurokawa

Description

@hkurokawa

I ran the below test code with RxJava 2.0.7 and got a failure which succeeded with RxJava 1.x.

    final TestObserver<Boolean> observer = TestObserver.create();
    Observable.<Boolean>create(emitter -> {
      emitter.onNext(Thread.interrupted());
      emitter.onComplete();
    })
        .delaySubscription(100, TimeUnit.MICROSECONDS)
        .subscribe(observer);
    observer.awaitTerminalEvent();
    observer.assertValue(false);
  }

If I put subscribeOn() before delaySubscription(), it does not fail.

I am not sure if it is as expected so want to know if it is the expected behaviour.

Here is some background of my issue: I am using RxJava 2.0.7 with Retrofit 2.2.0 and it seems Retrofit (precisely speaking, Okio, which is being used in OkHttp) throws an error when the thread is interrupted while it tries to read the HTTP response. I am trying to delay the HTTP call to achieve something like debounce() with delaySubscription() operator and encountered this issue. I have a workaround so just want to know if it is the expected behaviour.

Thank you for your support in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions