var source = new Subject();
source
.Take(1)
.Subscribe(Console.WriteLine);
source.OnNext(5);
source.OnNext(6);
source.OnError(new Exception("oops!"));
source.OnNext(7);
source.OnNext(8);
// Output is "5". Subscription is auto-disposed. Error is ignored.
Take
automatically disposes of the subscription after the nth
element yields. :)
As far as other things to consider, for your custom observable, you should note that you may also want to pass OnError and OnCompleted notifications to your observer, which Take also handles for you.
The built-in operators have other benefits as well, such as better Dispose
handling.