Exemplo n.º 1
0
        public DefinitionPromise(string definitionKey)
        {
            _promiseType = PromiseType.HoldsKey;

            this.definitionKey = definitionKey;
        }
        /// <summary>
        /// Sets the FamilyId from the current builder  to the promise.
        /// All of the promises within a method belong to the same family.
        /// </summary>
        /// <param name="builder">The instance of the current AsyncBuilder</param>
        /// <param name="promise">The promise to add to the family</param>
        public static void SetPromiseInfo(this IAsyncBuilder builder, IPromise promise, string familyId, PromiseType promiseType)
        {
            var basePomise = promise as BasePromiseInfo;

            if (basePomise != null)
            {
                basePomise.FamilyId    = familyId + UniqueIDGenerator.UniqueIdSeparator + builder.UniqueId;
                basePomise.PromiseType = promiseType;

                if (promiseType == PromiseType.Catch)
                {
                    basePomise.State = PromiseState.Skipped;
                }
                if (promiseType == PromiseType.Finally)
                {
                    basePomise.State = PromiseState.Default;
                }
            }
        }
        /// <summary>
        /// Adds a delegate and its respective promise to the list of promises to be validated.
        /// </summary>
        /// <param name="builder">The instance of the current AsyncBuilder</param>
        /// <param name="del">The original Delgate</param>
        /// <param name="promise">The promise associeted to the Delegate</param>
        /// <param name="promiseType">Indicates the type of promise added. By default is CodeExecution</param>
        public static void AddPromise(this IAsyncBuilder builder, Delegate del, IPromise promise, PromiseType promiseType = PromiseType.CodeExecution)
        {
            var delPromise = new DelegateOrPromise()
            {
                Delegate = del
            };

            delPromise.CreatedPromise = promise;
            builder.Delegates.Add(delPromise);
            builder.SetPromiseInfo(delPromise.CreatedPromise, builder.FamilyId, promiseType);
            builder.HasAppendedPromises = true;
        }
Exemplo n.º 4
0
 public Deferred()
 {
     _state  = PromiseType.None;
     Promise = new Promise <TOk, TErr>(this);
 }