Skip to content

Commit

Permalink
Extend Host and Hub with alternative methods
Browse files Browse the repository at this point in the history
- DiscoverAsync with Type instead of generics parameter
- Hub Deployment Verificatio with model provided

#161 non-breaking
  • Loading branch information
tthiery committed Apr 3, 2021
1 parent c7741b9 commit bb2a4e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/SharpBrick.PoweredUp/Deployment/HubExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ public static async Task VerifyDeploymentModelAsync(this Hub self, Action<Deploy

var model = BuildModel(configure);

await VerifyDeploymentModelAsync(self, model);
}

/// <summary>
/// Verifies the deployment model and waits till it reaches zero deployment errors.
/// </summary>
/// <param name="self"></param>
/// <param name="configure">Builder infrastructure for the deployment model</param>
/// <returns></returns>
public static async Task VerifyDeploymentModelAsync(this Hub self, DeploymentModel model)
{

var awaitable = self.VerifyObservable(model)
.Do(LogErrors(self))
.Where(x => x.Length == 0)
Expand Down
19 changes: 13 additions & 6 deletions src/SharpBrick.PoweredUp/PoweredUpHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,31 @@ public void Discover(Func<Hub, Task> onDiscovery, CancellationToken token = defa
}, token);
}

public async Task<THub> DiscoverAsync<THub>(CancellationToken token = default)
public async Task<THub> DiscoverAsync<THub>(CancellationToken token = default) where THub : class
=> await DiscoverInternalAsync(typeof(THub), token) as THub;

public async Task<Hub> DiscoverAsync(Type hubType, CancellationToken token = default)
=> await DiscoverInternalAsync(hubType, token);

private async Task<Hub> DiscoverInternalAsync(Type hubType, CancellationToken token)
{
var tcs = new TaskCompletionSource<THub>();
var tcs = new TaskCompletionSource<Hub>();

Discover(hub =>
{
if (hub is THub tHub)
var currentHubType = hub.GetType();
if (currentHubType == hubType)
{
tcs.SetResult(tHub);
tcs.SetResult(hub);
}
return Task.CompletedTask;
}, token);

var hub = await tcs.Task;

_logger.LogInformation($"End DiscoveryAsync for {typeof(THub).Name}");

_logger.LogInformation($"End DiscoveryAsync for {hubType.Name}");
return hub;
}

Expand Down

0 comments on commit bb2a4e5

Please sign in to comment.