ASOS / SimpleEventStore

SimpleEventStore
MIT License
81 stars 24 forks source link

CancellationToken can be passed to Task.Run in InMemoryStorageEngine. #62

Closed ElasticCoder closed 11 months ago

ElasticCoder commented 4 years ago

The CancellationToken can be passed to Task.Run in the InMemoryStorageEngine. Note the last parameter added to the code below.

return Task.Run(() =>
{
    if (!streams.ContainsKey(streamId))
    {
        streams[streamId] = new List<StorageEvent>();
    }

    var firstEvent = events.First();

    if (firstEvent.EventNumber - 1 != streams[streamId].
        {
            throw new ConcurrencyException($"Concurrency conflict when appending to stream {streamId}. Expected revision {firstEvent.EventNumber - 1} : Actual revision {streams[streamId].Count}");
    }

    cancellationToken.ThrowIfCancellationRequested();

    streams[streamId].AddRange(events);
    AddEventsToAllStream(events);
    }, 

    cancellationToken);