@@ -25,7 +25,7 @@ public class ProjectionUpdateBatch: IUpdateBatch, IAsyncDisposable, IDisposable,
25
25
private readonly DaemonSettings _settings ;
26
26
private readonly CancellationToken _token ;
27
27
private OperationPage ? _current ;
28
- private DocumentSessionBase ? _session ;
28
+ private DocumentSessionBase _session ;
29
29
30
30
private IMartenSession Session
31
31
{
@@ -41,6 +41,7 @@ private IMartenSession Session
41
41
internal ProjectionUpdateBatch ( DaemonSettings settings ,
42
42
DocumentSessionBase ? session , ShardExecutionMode mode , CancellationToken token )
43
43
{
44
+
44
45
_settings = settings ;
45
46
_session = session ?? throw new ArgumentNullException ( nameof ( session ) ) ;
46
47
_token = token ;
@@ -54,6 +55,12 @@ internal ProjectionUpdateBatch(DaemonSettings settings,
54
55
startNewPage ( session ) ;
55
56
}
56
57
58
+ public async Task InitializeMessageBatch ( )
59
+ {
60
+ _batch = await _session ! . Options . Events . MessageOutbox . CreateBatch ( _session ) . ConfigureAwait ( false ) ;
61
+ Listeners . Add ( _batch ) ;
62
+ }
63
+
57
64
public async Task WaitForCompletion ( )
58
65
{
59
66
Queue . Complete ( ) ;
@@ -335,25 +342,8 @@ protected void Dispose(bool disposing)
335
342
}
336
343
337
344
private IMessageBatch ? _batch ;
338
- private readonly SemaphoreSlim _semaphore = new ( 1 , 1 ) ;
339
- public async ValueTask < IMessageBatch > CurrentMessageBatch ( DocumentSessionBase session )
345
+ public ValueTask < IMessageBatch > CurrentMessageBatch ( DocumentSessionBase session )
340
346
{
341
- if ( _batch != null ) return _batch ;
342
-
343
- await _semaphore . WaitAsync ( _token ) . ConfigureAwait ( false ) ;
344
-
345
- if ( _batch != null ) return _batch ;
346
-
347
- try
348
- {
349
- _batch = await _session . Options . Events . MessageOutbox . CreateBatch ( session ) . ConfigureAwait ( false ) ;
350
- Listeners . Add ( _batch ) ;
351
-
352
- return _batch ;
353
- }
354
- finally
355
- {
356
- _semaphore . Release ( ) ;
357
- }
347
+ return new ValueTask < IMessageBatch > ( _batch ) ;
358
348
}
359
349
}
0 commit comments