/// <summary>
        /// Atomically tries to set the first value on the target field and returns
        /// false if its not null.
        /// </summary>
        /// <param name="field"></param>
        /// <param name="first"></param>
        /// <returns></returns>
        public static bool SetOnce(ref ISubscription field, ISubscription first)
        {
            for (;;)
            {
                ISubscription a = Volatile.Read(ref field);
                if (a == Cancelled)
                {
                    first?.Cancel();
                    return(false);
                }

                if (a != null)
                {
                    first?.Cancel();

                    OnSubscribeHelper.ReportSubscriptionSet();
                    return(false);
                }

                if (Interlocked.CompareExchange(ref field, first, null) == null)
                {
                    return(true);
                }
            }
        }
 public void OnSubscribe(ISubscription s)
 {
     if (SubscriptionHelper.SetOnce(ref this.other, s))
     {
         s.Request(long.MaxValue);
     }
     else
     {
         s.Cancel();
         OnSubscribeHelper.ReportSubscriptionSet();
     }
 }
            public void Set(ISubscription s)
            {
                ISubscription a = Interlocked.CompareExchange(ref secondSubscription, s, null);

                if (a == null)
                {
                    long r = Interlocked.Exchange(ref requested, 0);
                    if (r != 0)
                    {
                        s.Request(r);
                    }
                }
                else
                {
                    s?.Cancel();

                    if (a != SubscriptionHelper.Cancelled)
                    {
                        OnSubscribeHelper.ReportSubscriptionSet();
                    }
                }
            }