Skip to content

Commit 81202b3

Browse files
Make all table operations async (issue #54)
1 parent cba9f24 commit 81202b3

File tree

5 files changed

+78
-23
lines changed

5 files changed

+78
-23
lines changed

src/EventSourcingOnAzureFunctions.Common/EventSourcing/Implementation/AzureStorage/Table/TableEventStreamBase.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,24 @@ public async Task<bool> Exists()
126126
/// <remarks>
127127
/// We use the existence of the stream footer record as proof of stream existence
128128
/// </remarks>
129-
protected internal bool StreamAlreadyExists()
129+
protected async internal Task<bool> StreamAlreadyExists()
130130
{
131131
TableEntityKeyRecord streamFooter = null;
132132

133-
streamFooter = (TableEntityKeyRecord)Table.Execute(
134-
TableOperation.Retrieve<TableEntityKeyRecord>(this.InstanceKey, SequenceNumberAsString(0)),
135-
requestOptions: null,
136-
operationContext: GetDefaultOperationContext()).Result;
133+
TableOperation getKeyRecord = TableOperation.Retrieve<TableEntityKeyRecord>(this.InstanceKey, SequenceNumberAsString(0));
134+
135+
136+
TableResult getFooter = await Table.ExecuteAsync(
137+
getKeyRecord);
138+
139+
if (getFooter != null)
140+
{
141+
if (getFooter.Result != null)
142+
{
143+
streamFooter = (TableEntityKeyRecord)getFooter.Result;
144+
}
145+
}
146+
137147

138148
if (null != streamFooter)
139149
{

src/EventSourcingOnAzureFunctions.Common/EventSourcing/Implementation/AzureStorage/Table/TableEventStreamWriter.cs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,22 @@ public sealed class TableEventStreamWriter
1414
: TableEventStreamBase, IEventStreamWriter
1515
{
1616

17-
17+
/// <summary>
18+
/// Save an event onto the end of the event stream stored in Azure table
19+
/// </summary>
20+
/// <param name="eventInstance">
21+
/// The specific event to append to the end of the store
22+
/// </param>
23+
/// <param name="expectedTopSequenceNumber">
24+
/// If this is set and the sequence number of the event stream is higher then the event is
25+
/// not written
26+
/// </param>
27+
/// <param name="eventVersionNumber">
28+
/// The version number of the event being written
29+
/// </param>
30+
/// <param name="streamConstraint">
31+
/// Additional constraint that must be true if the event is to be appended
32+
/// </param>
1833
public async Task<IAppendResult> AppendEvent(IEvent eventInstance,
1934
int expectedTopSequenceNumber = 0,
2035
int eventVersionNumber = 1,
@@ -27,7 +42,7 @@ public async Task<IAppendResult> AppendEvent(IEvent eventInstance,
2742
if (streamConstraint != EventStreamExistenceConstraint.Loose )
2843
{
2944
// find out if the stream exists
30-
bool exists = StreamAlreadyExists();
45+
bool exists = await StreamAlreadyExists();
3146
if (streamConstraint== EventStreamExistenceConstraint.MustExist )
3247
{
3348
if (! exists )
@@ -108,10 +123,19 @@ private async Task<int> IncrementSequenceNumber()
108123
{
109124
tries += 1;
110125
// read in the a [TableEntityKeyRecord]
126+
TableOperation getKeyRecord = TableOperation.Retrieve<TableEntityKeyRecord>(this.InstanceKey, SequenceNumberAsString(0));
127+
111128

112-
streamFooter = (TableEntityKeyRecord)Table.Execute(
113-
TableOperation.Retrieve<TableEntityKeyRecord>(this.InstanceKey, SequenceNumberAsString(0)),
114-
operationContext: GetDefaultOperationContext()).Result;
129+
TableResult getFooter = await Table.ExecuteAsync(
130+
getKeyRecord );
131+
132+
if (getFooter != null)
133+
{
134+
if (getFooter.Result != null)
135+
{
136+
streamFooter = (TableEntityKeyRecord)getFooter.Result;
137+
}
138+
}
115139

116140
if (null == streamFooter)
117141
{
@@ -198,10 +222,19 @@ public async Task DeleteStream()
198222
{
199223
tries += 1;
200224
// read in the a [TableEntityKeyRecord]
225+
TableOperation getKeyRecord = TableOperation.Retrieve<TableEntityKeyRecord>(this.InstanceKey, SequenceNumberAsString(0));
226+
227+
228+
TableResult getFooter = await Table.ExecuteAsync(
229+
getKeyRecord);
201230

202-
streamFooter = (TableEntityKeyRecord)Table.Execute(
203-
TableOperation.Retrieve<TableEntityKeyRecord>(this.InstanceKey, SequenceNumberAsString(0)),
204-
operationContext: GetDefaultOperationContext()).Result;
231+
if (getFooter != null)
232+
{
233+
if (getFooter.Result != null)
234+
{
235+
streamFooter = (TableEntityKeyRecord)getFooter.Result;
236+
}
237+
}
205238

206239
if (null == streamFooter)
207240
{

src/EventSourcingOnAzureFunctions.Common/EventSourcingOnAzureFunctions.Common.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<PackageId>EventSourcingOnAzureFunctions.Common</PackageId>
6-
<PackageVersion>1.1</PackageVersion>
6+
<PackageVersion>1.2</PackageVersion>
77
<LangVersion>7.1</LangVersion>
88
<Authors>Duncan Jones</Authors>
99
<Description>Common function library to provide for event sourcing backed state management in Azure serverless functions</Description>
@@ -13,7 +13,7 @@
1313
<PackageTags>Event sourcing,serverless,azure functions</PackageTags>
1414
<Platforms>AnyCPU;x64</Platforms>
1515
<AssemblyVersion>1.1.0.0</AssemblyVersion>
16-
<Version>1.1</Version>
16+
<Version>1.2</Version>
1717
<IsPackable>true</IsPackable>
1818
<PackageReleaseNotes>Added notifications (via EventGrid) and CQRS scaffold</PackageReleaseNotes>
1919
<Copyright>2017-2021 Duncan Jones</Copyright>

src/EventSourcingOnAzureFunctions.Common/Notification/EventGridNotificationDispatcher.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,14 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
591591
}
592592

593593
/// <summary>
594-
/// Make a string that can be passed to the W3C Trace header as a trace paren
594+
/// Make a string that can be passed to the W3C Trace header as a trace parent
595595
/// </summary>
596596
/// <param name="correlationIdentifier">
597597
/// The string we used as our correlation identifier
598598
/// </param>
599599
/// <param name="causationIdentifier">
600600
/// The string we used as our causation identifier
601601
/// </param>
602-
/// <returns>
603-
///
604-
/// </returns>
605602
/// <remarks>
606603
/// See https://www.w3.org/TR/trace-context/#examples-of-http-traceparent-headers
607604
/// </remarks>

src/EventSourcingOnAzureFunctions.Common/doc/EventSourcingOnAzureFunctions.Common.xml

Lines changed: 19 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)