Beispiel #1
0
        /// <summary>
        /// Invoke the scorable calling protocol against a single scorable.
        /// </summary>
        public static async Task <bool> TryPostAsync <Item, Score>(this IScorable <Item, Score> scorable, Item item, CancellationToken token)
        {
            var state = await scorable.PrepareAsync(item, token);

            try
            {
                if (scorable.HasScore(item, state))
                {
                    var score = scorable.GetScore(item, state);
                    await scorable.PostAsync(item, state, token);

                    return(true);
                }

                return(false);
            }
            finally
            {
                await scorable.DoneAsync(item, state, token);
            }
        }