< Summary

Class:DCL.Helpers.AsyncEnumerableWithEvent[T]
Assembly:UniTaskUtils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/TaskUtils/UniTaskUtils/AsyncEnumerableWithEvent.cs
Covered lines:0
Uncovered lines:12
Coverable lines:12
Total lines:43
Line coverage:0% (0 of 12)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:6
Method coverage:0% (0 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AsyncEnumerableWithEvent()0%2100%
AddListener(...)0%2100%
RemoveListener(...)0%2100%
Write(...)0%6200%
GetAsyncEnumerator(...)0%2100%
Dispose()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Utils/TaskUtils/UniTaskUtils/AsyncEnumerableWithEvent.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using System;
 3using System.Threading;
 4
 5namespace DCL.Helpers
 6{
 7    public interface IAsyncEnumerableWithEvent<T> : IUniTaskAsyncEnumerable<T>
 8    {
 9        void AddListener(Action<T> callback);
 10        void RemoveListener(Action<T> callback);
 11    }
 12
 13    public class AsyncEnumerableWithEvent<T> : IAsyncEnumerableWithEvent<T>, IDisposable
 14    {
 015        private readonly AsyncReactiveProperty<T> activeProperty = new (default);
 16        private Action<T> callback;
 17
 18        public void AddListener(Action<T> callback)
 19        {
 020            this.callback += callback;
 021        }
 22
 23        public void RemoveListener(Action<T> callback)
 24        {
 025            this.callback -= callback;
 026        }
 27
 28        public void Write(T item)
 29        {
 030            callback?.Invoke(item);
 031            activeProperty.Value = item;
 032        }
 33
 34        public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = new ()) =>
 035            activeProperty.WithoutCurrent().GetAsyncEnumerator(cancellationToken);
 36
 37        public void Dispose()
 38        {
 039            activeProperty?.Dispose();
 040            callback = null;
 041        }
 42    }
 43}