Created
January 26, 2012 00:19
-
-
Save anaisbetts/1679956 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static IObservable<RecoveryOptionResult> Throw(UserError error) | |
| { | |
| var handlers = (overriddenRegisteredUserErrorHandlers != null) ? | |
| new[] { overriddenRegisteredUserErrorHandlers } : | |
| registeredUserErrorHandlers.ToArray().Reverse(); | |
| // NB: This is a little complicated - here's the idea: we have a | |
| // list of handlers that we're running down *in order*. If we find | |
| // one that doesn't return null, we're going to return this as an | |
| // Observable with one item (the result). | |
| // | |
| // If *none* of the handlers are interested in this UserError, we're | |
| // going to OnError the Observable. | |
| var ret = handlers.ToObservable() | |
| .Select(handler => Observable.Start(() => handler(error), RxApp.DeferredScheduler)) | |
| .Concat() | |
| .Where(x => x != null).Select(x => x.Value) | |
| .Concat(Observable.Throw<RecoveryOptionResult>(new UnhandledUserErrorException(error))) | |
| .Take(1) | |
| .Multicast(new AsyncSubject<RecoveryOptionResult>()); | |
| ret.Connect(); | |
| return ret; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment