Skip to content

Instantly share code, notes, and snippets.

@anaisbetts
Created January 26, 2012 00:19
Show Gist options
  • Select an option

  • Save anaisbetts/1679956 to your computer and use it in GitHub Desktop.

Select an option

Save anaisbetts/1679956 to your computer and use it in GitHub Desktop.
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