/// <summary> /// 异步设置对象锁定期结束时间。 /// </summary> /// <param name="lockout">给定的 <see cref="IObjectLockout"/>。</param> /// <param name="newLockoutEndFactory">给定的新对象锁定期结束时间工厂方法。</param> /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param> /// <returns>返回一个包含锁定期结束时间(提供对 <see cref="DateTime"/> 或 <see cref="DateTimeOffset"/> 的支持)的异步操作。</returns> public static async ValueTask <object> SetObjectLockoutEndAsync(this IObjectLockout lockout, Func <object, object> newLockoutEndFactory, CancellationToken cancellationToken = default) { var currentLockoutEnd = await lockout.GetObjectLockoutEndAsync(cancellationToken).DisableAwaitContext(); return(await lockout.SetObjectLockoutEndAsync(newLockoutEndFactory(currentLockoutEnd), cancellationToken) .DisableAwaitContext()); }
public static async ValueTask <object> SetObjectLockoutEndAsync(this IObjectLockout lockout, Func <object, object> newLockoutEndFactory, CancellationToken cancellationToken = default) { lockout.NotNull(nameof(lockout)); newLockoutEndFactory.NotNull(nameof(newLockoutEndFactory)); var newLockoutEnd = await lockout.GetObjectLockoutEndAsync(cancellationToken).ConfigureAwait(); return(await lockout.SetObjectLockoutEndAsync(newLockoutEndFactory.Invoke(newLockoutEnd), cancellationToken) .ConfigureAwait()); }