Skip to content

Unsubscribe from takeLast #521

@samuelgruetter

Description

@samuelgruetter

When I unsubscribe from an Observable which emits the last value of an infinite stream, I expect to get no element. This is the case in C#:

var o = Observable.Interval(TimeSpan.FromMilliseconds(200)).TakeLast(1);
var s = o.Subscribe(i => Console.WriteLine("Interesting: Infinity = " + i));
Thread.Sleep(1000);
s.Dispose();
Thread.Sleep(1000);
Console.WriteLine("Press any key...");
Console.ReadKey();

outputs

Press any key...

But with RxJava, it's different (note that Scala's takeRight calls Java's takeLast):

val o = Observable.interval(200 millis).takeRight(1)
val s = o.subscribe(i => println(s"Interesting: Infinity = $i"))
Thread.sleep(1000)
s.unsubscribe()
Thread.sleep(1000)  

outputs

Interesting: Infinity = 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions