< Summary

Class:DCL.Helpers.Promise[T]
Assembly:Promise
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Promise/Promise.cs
Covered lines:26
Uncovered lines:1
Coverable lines:27
Total lines:57
Line coverage:96.2% (26 of 27)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Resolve(...)0%220100%
Reject(...)0%2.032080%
Then(...)0%440100%
Catch(...)0%440100%
Dispose()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/Promise/Promise.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3
 4namespace DCL.Helpers
 5{
 6    public class Promise<T> : CustomYieldInstruction, IDisposable
 7    {
 34468        internal bool resolved { get; private set; }
 7529        internal bool failed { get; private set; }
 48710        internal PromiseException exception { get; private set; }
 11
 12        internal Action<T> onSuccess;
 13        internal Action<string> onError;
 14
 244715        public override bool keepWaiting => !resolved;
 80216        public T value { private set; get; }
 617        public string error => exception?.Message;
 18
 19        public void Resolve(T result)
 20        {
 48021            failed = false;
 48022            resolved = true;
 48023            value = result;
 48024            exception = null;
 48025            onSuccess?.Invoke(result);
 24026        }
 27
 28        public void Reject(string errorMessage)
 29        {
 130            failed = true;
 131            resolved = true;
 132            exception = new PromiseException(errorMessage);
 133            onError?.Invoke(error);
 034        }
 35
 36        public Promise<T> Then(Action<T> successCallback)
 37        {
 68438            if (!resolved) { onSuccess = successCallback; }
 40339            else if (!failed) { successCallback?.Invoke(value); }
 40
 44341            return this;
 42        }
 43
 44        public void Catch(Action<string> errorCallback)
 45        {
 546            if (!resolved) { onError = errorCallback; }
 247            else if (failed) { errorCallback?.Invoke(this.error); }
 148        }
 49
 50        public void Dispose()
 51        {
 452            onSuccess = null;
 453            onError = null;
 454            resolved = true;
 455        }
 56    }
 57}