diff options
Diffstat (limited to 'src/Agent.Core/Sessions/SessionStore.cs')
| -rw-r--r-- | src/Agent.Core/Sessions/SessionStore.cs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/Agent.Core/Sessions/SessionStore.cs b/src/Agent.Core/Sessions/SessionStore.cs new file mode 100644 index 0000000..59ea02c --- /dev/null +++ b/src/Agent.Core/Sessions/SessionStore.cs @@ -0,0 +1,19 @@ +using System.Collections.Concurrent; + +namespace Agent.Core.Sessions; + +public sealed class SessionStore +{ + private readonly ConcurrentDictionary<Guid, AgentSession> _sessions = new(); + + public AgentSession Create() + { + while (true) + { + var session = new AgentSession(Guid.NewGuid()); + if (_sessions.TryAdd(session.SessionId, session)) return session; + } + } + + public bool TryGet(Guid sessionId, out AgentSession? session) => _sessions.TryGetValue(sessionId, out session); +} |
