mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using Squidex.Infrastructure;
|
|
|
|
namespace Squidex.Web
|
|
{
|
|
public readonly struct Deferred
|
|
{
|
|
private readonly Lazy<Task<object>> value;
|
|
|
|
public Task<object> Value
|
|
{
|
|
get => value.Value;
|
|
}
|
|
|
|
private Deferred(Func<Task<object>> value)
|
|
{
|
|
this.value = new Lazy<Task<object>>(value);
|
|
}
|
|
|
|
public static Deferred Response(Func<object> factory)
|
|
{
|
|
Guard.NotNull(factory);
|
|
|
|
return new Deferred(() => Task.FromResult(factory()));
|
|
}
|
|
|
|
public static Deferred AsyncResponse<T>(Func<Task<T>> factory)
|
|
{
|
|
Guard.NotNull(factory);
|
|
|
|
return new Deferred(async () => (await factory())!);
|
|
}
|
|
}
|
|
}
|
|
|