public static IRadicalYieldInstruction Wait(this ISPAnim anim, SPTimePeriod period, bool stopAnimOnComplete)
        {
            if (anim == null)
            {
                throw new System.ArgumentNullException("anim");
            }

            if (!anim.IsPlaying || period.Seconds <= 0f)
            {
                return(null);                                         //yielding to when a non-playing anim finishes is just one frame, yield null
            }
            if (period.Seconds == float.PositiveInfinity && anim is IRadicalYieldInstruction)
            {
                return(anim as IRadicalYieldInstruction); //SPAnim can be used directly as a yield instruction to its end
            }
            else
            {
                var handle = RadicalWaitHandle.Create();
                anim.Schedule((a) =>
                {
                    if (stopAnimOnComplete && a.IsPlaying)
                    {
                        a.Stop();
                    }
                    handle.SignalComplete();
                }, period.Seconds, period.TimeSupplier);
                return(handle);
            }
        }
 public IRadicalWaitHandle Wait()
 {
     if (_handle == null)
     {
         _handle = RadicalWaitHandle.Create();
     }
     return(_handle);
 }
        public override bool Trigger(object arg)
        {
            if (!this.CanTrigger)
            {
                return(false);
            }

            if (_handle != null)
            {
                _handle.SignalComplete();
                _handle = null;
            }

            return(true);
        }