using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; namespace ComposableAsync { /// /// extension methods provider /// public static class DispatcherExtension { /// /// Returns awaitable to enter in the dispatcher context /// This extension method make a dispatcher awaitable /// /// /// public static DispatcherAwaiter GetAwaiter(this IDispatcher dispatcher) { return new DispatcherAwaiter(dispatcher); } /// /// Returns a composed dispatcher applying the given dispatcher /// after the first one /// /// /// /// public static IDispatcher Then(this IDispatcher dispatcher, IDispatcher other) { if (dispatcher == null) throw new ArgumentNullException(nameof(dispatcher)); if (other == null) throw new ArgumentNullException(nameof(other)); return new ComposedDispatcher(dispatcher, other); } /// /// Returns a composed dispatcher applying the given dispatchers sequentially /// /// /// /// public static IDispatcher Then(this IDispatcher dispatcher, params IDispatcher[] others) { return dispatcher.Then((IEnumerable)others); } /// /// Returns a composed dispatcher applying the given dispatchers sequentially /// /// /// /// public static IDispatcher Then(this IDispatcher dispatcher, IEnumerable others) { if (dispatcher == null) throw new ArgumentNullException(nameof(dispatcher)); if (others == null) throw new ArgumentNullException(nameof(others)); return others.Aggregate(dispatcher, (cum, val) => cum.Then(val)); } /// /// Create a from an /// /// /// public static DelegatingHandler AsDelegatingHandler(this IDispatcher dispatcher) { return new DispatcherDelegatingHandler(dispatcher); } /// /// Create a from an /// /// /// public static IDispatcher ToFullDispatcher(this IBasicDispatcher @basicDispatcher) { return new DispatcherAdapter(@basicDispatcher); } } }