public Task <IEventId> AppendToStream(string subject, byte[] payload) { var streamId = _eventSerializer.GetAggregateId(subject); var eventID = _eventIdProvider.Next(streamId, subject); var stream = _cache.GetOrAdd(streamId, (_) => { return(new SortedList <long, IEventCacheItem>()); }); stream.Add(eventID.Version, new EventCacheItem() { Message = payload, EventId = eventID }); return(Task.FromResult(eventID)); }
public ValueTask <EventId> AppendToStream(byte[] subject, byte[] payload) { var subjectAsString = Encoding.UTF8.GetString(subject); var streamId = _eventSerializer.GetAggregateId(subjectAsString); var eventID = _eventIdProvider.Next(streamId, subjectAsString); var stream = _cache.GetOrAdd(streamId, (_) => { return(new SortedList <long, EventCacheItem>()); }); //todo : should have a lock per streamId lock (_lock) { stream.Add(eventID.Version, new EventCacheItem() { Message = payload, EventId = eventID }); } return(new ValueTask <EventId>(eventID)); }