Ejemplo n.º 1
0
    /// <summary>
    /// 异步设置对象排名。
    /// </summary>
    /// <param name="ranking">给定的 <see cref="IObjectRanking"/>。</param>
    /// <param name="newRankFactory">给定的新对象排名工厂方法。</param>
    /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param>
    /// <returns>返回一个包含排名(兼容整数、单双精度的排序字段)的异步操作。</returns>
    public static async ValueTask <object> SetObjectRankAsync(this IObjectRanking ranking,
                                                              Func <object, object> newRankFactory, CancellationToken cancellationToken = default)
    {
        var currentRank = await ranking.GetObjectRankAsync(cancellationToken)
                          .DisableAwaitContext();

        return(await ranking.SetObjectRankAsync(newRankFactory(currentRank),
                                                cancellationToken).DisableAwaitContext());
    }
Ejemplo n.º 2
0
        public static async ValueTask <object> SetObjectRankAsync(this IObjectRanking ranking,
                                                                  Func <object, object> newRankFactory, CancellationToken cancellationToken = default)
        {
            ranking.NotNull(nameof(ranking));
            newRankFactory.NotNull(nameof(newRankFactory));

            var newRank = await ranking.GetObjectRankAsync(cancellationToken).ConfigureAwait();

            return(await ranking.SetObjectRankAsync(newRankFactory.Invoke(newRank), cancellationToken)
                   .ConfigureAwait());
        }