コード例 #1
0
        public async Task <IDisposable> Subscribe(TCriteria criteria,
                                                  ReactiveActions <TActionArgument> actions)
        {
            var cacheElement = new ResubscribeCacheElement <TCriteria, TActionArgument>(criteria, actions);

            cache.Add(cacheElement);

            await TrySubscribeOnCacheElement(cacheElement).ConfigureAwait(false);

            return(cacheElement);
        }
コード例 #2
0
        protected async Task <bool> TrySubscribeOnCacheElement(ResubscribeCacheElement <TCriteria, TActionArgument> cacheElement, bool isReSubscribe = false)
        {
            try
            {
                var providerSubscription = await wrappedProvider.Subscribe(cacheElement.Criteria,
                                                                           cacheElement.Actions.NextAction,
                                                                           cacheElement.Actions.ErrorAction).ConfigureAwait(false);

                cacheElement.MakeSubscriptionAlive(providerSubscription);

                if (isReSubscribe)
                {
                    await OnReSubscribed(cacheElement.Criteria, cacheElement.Actions.NextAction, cacheElement.Actions.ErrorAction).ConfigureAwait(false);
                }

                return(true);
            }
            catch (Exception e)
            {
                cacheElement.MakeSubscriptionRotten();
                DoOnException(e);
                return(false);
            }
        }