Programming Reactive Extensions and LINQ by Jesse Liberty Paul Betts

Programming Reactive Extensions and LINQ by Jesse Liberty Paul Betts

Author:Jesse Liberty, Paul Betts
Language: eng
Format: epub
Publisher: Apress®
Published: 2011-10-24T16:00:00+00:00


If you choose to make the error disappear, you can use the Retry method. To follow abort semantics, use the Repeat method. If you want a new Observable every time something bad happens, use the Defer() method, as shown in the next example,

int counter = 0;

var input = Observable.Defer(() => {

// Simulate an Observable that sometimes dies

if (++counter % 2 == 0) {

return Observable.Throw<int>(new Exception("Aieeee!"));

} else {

return Observable.Return(42);

}

});

input.Subscribe(x => Console.WriteLine(x), ex => Console.WriteLine(ex.Message));

input.Subscribe(x => Console.WriteLine(x), ex => Console.WriteLine(ex.Message));

input.Subscribe(x => Console.WriteLine(x), ex => Console.WriteLine(ex.Message));

The following is the console output you can expect to see:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.