views:

86

answers:

1

Is there a shorthand version of this. I want to call one sequence and then when it is finished call another.

var seq1 = Observable.Range(1, 20);
var seq2 = Observable.Range(21, 20);

seq1.Subscribe(
    i  => Console.WriteLine(i), 
    () => seq2.Subscribe(i => Console.WriteLine(i)));
+2  A: 

It's not entirely clear to me what you're trying to do (and I don't have the docs to hand) but is Observables.Concat what you're after?

var seq1 = Observable.Range(1, 20);
var seq2 = Observable.Range(21, 20);
var both = seq1.Concat(seq2);
both.Subscribe(i => Console.WriteLine(i));

(I'm just checking that this actually works :)

Jon Skeet
Since he has 20 as the end of seq1 and 21 the start of seq2 then Concat is correct.
Richard Hein
Not trying to do anything but get 2 observables to execute one after another. This appears to do what I want in this case but what if the 2 observables where different types?
kouPhax
@kouPhax: I'm not entirely sure how you'd want to use that. Could you give an example of what you'd *want* to be able to write?
Jon Skeet
To be honest that's it.... rather than any real world scenario I was writing some small Linq 101 style examples and was wondering if it was possible to chain Observables based on OnComplete firing. There is probably no real world application as you say but it just made me think.Thanks for the response.
kouPhax