Add additional RunAsync overloads (#4286)

This commit is contained in:
Mikhail Shilkov 2020-04-09 16:43:43 +02:00 committed by GitHub
parent ca6e47277f
commit 46dababc28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 13 deletions

View file

@ -29,6 +29,9 @@ CHANGELOG
- Add overloads to Output.All in .NET
[#4321](https://github.com/pulumi/pulumi/pull/4321)
- Add additional overloads to Deployment.RunAsync in .NET API.
[#4286](https://github.com/pulumi/pulumi/pull/4286)
## 1.14.0 (2020-04-01)
- Fix error related to side-by-side versions of `@pulumi/pulumi`.
[#4235](https://github.com/pulumi/pulumi/pull/4235)

View file

@ -45,9 +45,9 @@ namespace Pulumi
return WhileRunningAsync();
}
public Task<int> RunAsync(Func<Task<IDictionary<string, object?>>> func)
public Task<int> RunAsync(Func<Task<IDictionary<string, object?>>> func, StackOptions? options)
{
var stack = new Stack(func);
var stack = new Stack(func, options);
RegisterTask("User program code.", stack.Outputs.DataTask);
return WhileRunningAsync();
}

View file

@ -12,8 +12,9 @@ namespace Pulumi
public partial class Deployment
{
/// <summary>
/// <see cref="RunAsync(Func{Task{IDictionary{string, object}}})"/> for more details.
/// <see cref="RunAsync(Func{Task{IDictionary{string, object}}}, StackOptions)"/> for more details.
/// </summary>
/// <param name="action">Callback that creates stack resources.</param>
public static Task<int> RunAsync(Action action)
=> RunAsync(() =>
{
@ -22,15 +23,26 @@ namespace Pulumi
});
/// <summary>
/// <see cref="RunAsync(Func{Task{IDictionary{string, object}}})"/> for more details.
/// <see cref="RunAsync(Func{Task{IDictionary{string, object}}}, StackOptions)"/> for more details.
/// </summary>
/// <param name="func"></param>
/// <returns></returns>
/// <param name="func">Callback that creates stack resources.</param>
/// <returns>A dictionary of stack outputs.</returns>
public static Task<int> RunAsync(Func<IDictionary<string, object?>> func)
=> RunAsync(() => Task.FromResult(func()));
/// <summary>
/// <see cref="RunAsync(Func{Task{IDictionary{string, object}}}, StackOptions)"/> for more details.
/// </summary>
/// <param name="func">Callback that creates stack resources.</param>
public static Task<int> RunAsync(Func<Task> func)
=> RunAsync(async () =>
{
await func();
return ImmutableDictionary<string, object?>.Empty;
});
/// <summary>
/// <see cref="RunAsync(Func{Task{IDictionary{string, object}}})"/> is an
/// <see cref="RunAsync(Func{Task{IDictionary{string, object}}}, StackOptions)"/> is an
/// entry-point to a Pulumi application. .NET applications should perform all startup logic
/// they need in their <c>Main</c> method and then end with:
/// <para>
@ -53,12 +65,14 @@ namespace Pulumi
/// the running of the program are properly reported. Failure to do this may lead to the
/// program ending early before all resources are properly registered.
/// <para/>
/// The function passed to <see cref="RunAsync(Func{Task{IDictionary{string, object}}})"/>
/// The function passed to <see cref="RunAsync(Func{Task{IDictionary{string, object}}}, StackOptions)"/>
/// can optionally return an <see cref="IDictionary{TKey, TValue}"/>. The keys and values
/// in this dictionary will become the outputs for the Pulumi Stack that is created.
/// </summary>
public static Task<int> RunAsync(Func<Task<IDictionary<string, object?>>> func)
=> CreateRunner().RunAsync(func);
/// <param name="func">Callback that creates stack resources.</param>
/// <param name="options">Stack options.</param>
public static Task<int> RunAsync(Func<Task<IDictionary<string, object?>>> func, StackOptions? options = null)
=> CreateRunner().RunAsync(func, options);
/// <summary>
/// <see cref="RunAsync{TStack}()"/> is an entry-point to a Pulumi

View file

@ -9,7 +9,7 @@ namespace Pulumi
internal interface IRunner
{
void RegisterTask(string description, Task task);
Task<int> RunAsync(Func<Task<IDictionary<string, object?>>> func);
Task<int> RunAsync(Func<Task<IDictionary<string, object?>>> func, StackOptions? options);
Task<int> RunAsync<TStack>() where TStack : Stack, new();
}
}

View file

@ -227,7 +227,8 @@ static Pulumi.CustomResourceOptions.Merge(Pulumi.CustomResourceOptions options1,
static Pulumi.Deployment.Instance.get -> Pulumi.IDeployment
static Pulumi.Deployment.RunAsync(System.Action action) -> System.Threading.Tasks.Task<int>
static Pulumi.Deployment.RunAsync(System.Func<System.Collections.Generic.IDictionary<string, object>> func) -> System.Threading.Tasks.Task<int>
static Pulumi.Deployment.RunAsync(System.Func<System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<string, object>>> func) -> System.Threading.Tasks.Task<int>
static Pulumi.Deployment.RunAsync(System.Func<System.Threading.Tasks.Task> func) -> System.Threading.Tasks.Task<int>
static Pulumi.Deployment.RunAsync(System.Func<System.Threading.Tasks.Task<System.Collections.Generic.IDictionary<string, object>>> func, Pulumi.StackOptions options = null) -> System.Threading.Tasks.Task<int>
static Pulumi.Deployment.RunAsync<TStack>() -> System.Threading.Tasks.Task<int>
static Pulumi.Deployment.TestAsync<TStack>(Pulumi.Testing.IMocks mocks, Pulumi.Testing.TestOptions options = null) -> System.Threading.Tasks.Task<System.Collections.Immutable.ImmutableArray<Pulumi.Resource>>
static Pulumi.Input<T>.implicit operator Pulumi.Input<T>(Pulumi.Output<T> value) -> Pulumi.Input<T>

View file

@ -63,7 +63,7 @@ namespace Pulumi
/// An instance of this will be automatically created when any <see
/// cref="Deployment.RunAsync(Action)"/> overload is called.
/// </summary>
internal Stack(Func<Task<IDictionary<string, object?>>> init) : this()
internal Stack(Func<Task<IDictionary<string, object?>>> init, StackOptions? options) : this(options)
{
try
{