Exemple #1
0
 static async Task P_DoSingleMessagePostingAsync(LocalPostingToken token, ILocalSubscription subscription, CancellationToken ct)
 {
     token.EnsureNotNull(nameof(token));
     subscription.EnsureNotNull(nameof(subscription));
     //
     if (subscription.IsActive)
     {
         ILocalSubscriber subscriber;
         try {
             subscriber = subscription.Subscriber;
         }
         catch (ObjectDisposedException) {
             if (subscription.IsActive)
             {
                 throw;
             }
             else
             {
                 return;
             }
         }
         //
         using (var context = ContextUtilities.Create(ct: ct))
             await subscriber.ProcessMessagePostAsync(subscription : subscription, message : token.Message, ctx : context).ConfigureAwait(false);
         //
         token.NotifySubscriptionPosted();
     }
 }
Exemple #2
0
        internal LocalPostingQueueEntry(LocalPostingToken postingToken, IEnumerable <ILocalSubscription> postingSubscriptions)
        {
            postingToken.EnsureNotNull(nameof(postingToken));
            var locPostingSubscriptions = postingSubscriptions.EnsureNotNull(nameof(postingSubscriptions)).EnsureNoNullElements().Value.ToList();

            //
            _postingToken                 = postingToken;
            _postingSubscriptions         = locPostingSubscriptions;
            _postingSubscriptionsSpinLock = new PrimitiveSpinLock();
        }
Exemple #3
0
 public bool TryGetNextPostingSubscription(out LocalPostingToken postingToken, out ILocalSubscription postingSubscription)
 {
     if (TryReadDA(ref _postingSubscriptionsSpinLock, considerDisposeRequest: true, result: out var subscriptionsSpinLock) &&
         TryReadDA(ref _postingSubscriptions, considerDisposeRequest: true, result: out var subscriptions) &&
         TryReadDA(ref _postingToken, considerDisposeRequest: true, result: out var locPostingToken))
     {
         //
         var locPostingSubscription =
             subscriptionsSpinLock
             .Invoke(
                 () => {
             if (subscriptions.Count < 1)
             {
                 return(null);
             }
             else
             {
                 return(subscriptions.RemoveItemAt(index: 0));
             }
         });
         postingSubscription = locPostingSubscription;
         postingToken        = locPostingSubscription == null ? null : locPostingToken;
         return(locPostingSubscription != null);
     }