forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88a5696
commit 6f8b6b7
Showing
15 changed files
with
393 additions
and
228 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/ResourceManager/Common/Commands.Common.Strategies/AsyncOperationContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.Commands.Common.Strategies | ||
{ | ||
sealed class AsyncOperationContext | ||
{ | ||
public IClient Client { get; } | ||
|
||
public CancellationToken CancellationToken { get; } | ||
|
||
public IState Result => State; | ||
|
||
public AsyncOperationContext(IClient client, CancellationToken cancellationToken) | ||
{ | ||
Client = client; | ||
CancellationToken = cancellationToken; | ||
} | ||
|
||
public async Task<Model> GetOrAdd<Model>( | ||
ResourceConfig<Model> config, Func<Task<Model>> create) | ||
where Model : class | ||
{ | ||
var result = await TaskMap.GetOrAdd( | ||
config.DefaultIdStr(), | ||
async _ => | ||
{ | ||
var model = await create(); | ||
if (model != null) | ||
{ | ||
State.GetOrAdd(config, () => model); | ||
} | ||
return model; | ||
}); | ||
return result as Model; | ||
} | ||
|
||
State State { get; } = new State(); | ||
|
||
ConcurrentDictionary<string, Task<object>> TaskMap { get; } | ||
= new ConcurrentDictionary<string, Task<object>>(); | ||
} | ||
} |
55 changes: 0 additions & 55 deletions
55
src/ResourceManager/Common/Commands.Common.Strategies/AsyncOperationVisitor.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/ResourceManager/Common/Commands.Common.Strategies/Extensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.