Skip to content

Commit 1c51d52

Browse files
committed
Adding an information if group was created while adding a client (#23)
1 parent 73c3ab1 commit 1c51d52

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

Lib.AspNetCore.ServerSentEvents/IServerSentEventsService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public interface IServerSentEventsService
5656
/// </summary>
5757
/// <param name="groupName">The group name.</param>
5858
/// <param name="client">The client to add to a group.</param>
59-
Task AddToGroupAsync(string groupName, IServerSentEventsClient client);
59+
/// <returns>The task object representing the result of asynchronous operation</returns>
60+
Task<ServerSentEventsAddToGroupResult> AddToGroupAsync(string groupName, IServerSentEventsClient client);
6061

6162
/// <summary>
6263
/// Changes the interval after which clients will attempt to reestablish failed connections.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Lib.AspNetCore.ServerSentEvents
2+
{
3+
/// <summary>
4+
/// The add to group results.
5+
/// </summary>
6+
public enum ServerSentEventsAddToGroupResult
7+
{
8+
/// <summary>
9+
/// The client has been added to an existing group.
10+
/// </summary>
11+
AddedToExistingGroup = 1,
12+
/// <summary>
13+
/// The client has been added to a new group.
14+
/// </summary>
15+
AddedToNewGroup = 2
16+
}
17+
}

Lib.AspNetCore.ServerSentEvents/ServerSentEventsService.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,22 @@ public IReadOnlyCollection<IServerSentEventsClient> GetClients(string groupName)
114114
/// Adds a client to the specified group.
115115
/// </summary>
116116
/// <param name="groupName">The group name.</param>
117-
/// <param name="client">The client to add to a group.</param>
118-
public async Task AddToGroupAsync(string groupName, IServerSentEventsClient client)
117+
/// /// <param name="client">The client to add to a group.</param>
118+
/// <returns>The task object representing the result of asynchronous operation</returns>
119+
public async Task<ServerSentEventsAddToGroupResult> AddToGroupAsync(string groupName, IServerSentEventsClient client)
119120
{
121+
ServerSentEventsAddToGroupResult result = ServerSentEventsAddToGroupResult.AddedToExistingGroup;
122+
120123
if (!_groups.ContainsKey(groupName))
121124
{
122125
await CreateGroupAsync(groupName);
126+
127+
result = ServerSentEventsAddToGroupResult.AddedToNewGroup;
123128
}
124129

125130
_groups[groupName].TryAdd(client.Id, client);
131+
132+
return result;
126133
}
127134

128135
/// <summary>

0 commit comments

Comments
 (0)