Example #1
0
        public async Task <bool> WaitAsync(CancellationToken cancellationToken = default)
        {
            var queue = new TaskCompletionQueuedSource <T>();

            void SubscribeOnChange(T newValue) => queue.NewData(newValue);

            try
            {
                OnChange.Add(SubscribeOnChange);
                if (await queue.WaitValueAsync(cancellationToken).ConfigureAwait(false) is var result && result.Ok)
                {
                    Value = result.Value;
                }
                return(result.Ok);
            }
            finally
            {
                OnChange.Remove(SubscribeOnChange);
            }
        }