Skip to content

Commit

Permalink
add StopManuallyAsync to HostManager
Browse files Browse the repository at this point in the history
  • Loading branch information
amelkor committed May 3, 2023
1 parent 81580cf commit a6143c0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Microsoft.Extensions.Hosting for Unity

## [2.1.0] - 2023-04-09
## [2.1.0] - 2023-05-03
### Added
- Scoped MonoBehaviours
- MonoBehaviour prefabs registration by prefab name from Resources
- ScriptableObjectConfiguration as configuration source
- `MonoBehaviour` prefabs registration by prefab name from Resources
- `ScriptableObjectConfiguration` as configuration source
- hostBuilding event when the host is being built
- `StopManuallyAsync` method to `HostManager`
### Updated
- make HostManager events public

Expand Down
20 changes: 19 additions & 1 deletion Runtime/HostManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void StartManually()
}

/// <summary>
/// Start the Host manually.
/// Stop the Host manually.
/// </summary>
/// <exception cref="InvalidOperationException">when the Host was not build and started yet.</exception>
public void StopManually()
Expand All @@ -209,6 +209,24 @@ public void StopManually()
host.StopAsync().GetAwaiter().GetResult();
}
}

/// <summary>
/// Stop the Host manually.
/// </summary>
/// <exception cref="InvalidOperationException">when the Host was not build and started yet.</exception>
public Task StopManuallyAsync()
{
if (!_isBuilt && !_isStarted)
throw new InvalidOperationException("Host must be build and started before stop.");

if (host != null)
{
_cts?.Cancel();
return host.StopAsync();
}

return Task.CompletedTask;
}

#endregion

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Microsoft.Extensions.Hosting adopted for Unity",
"unity": "2021.1",
"release": "0f1",
"version": "2.1.0-preview.3",
"version": "2.1.0-preview.4",
"keywords": [
"unity",
"integration",
Expand Down

0 comments on commit a6143c0

Please sign in to comment.