forked from zarusz/SlimMessageBus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zarusz#275 Notify outbox service that a message is available for publ…
…ishing Signed-off-by: Richard Pringle <[email protected]>
- Loading branch information
Showing
23 changed files
with
678 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
namespace SlimMessageBus.Host.Outbox; | ||
|
||
public sealed class AsyncManualResetEvent | ||
{ | ||
private readonly object _lock; | ||
private TaskCompletionSource<bool> _tcs; | ||
|
||
public AsyncManualResetEvent(bool initialState = false) | ||
{ | ||
_lock = new object(); | ||
_tcs = new TaskCompletionSource<bool>(); | ||
|
||
if (initialState) | ||
{ | ||
_tcs.SetResult(true); | ||
} | ||
} | ||
|
||
public async Task<bool> Wait(int millisecondsDelay = -1, CancellationToken cancellationToken = default) | ||
{ | ||
Task GetTask() | ||
{ | ||
lock (_lock) | ||
{ | ||
return _tcs.Task; | ||
} | ||
} | ||
|
||
var resetEvent = GetTask(); | ||
var task = await Task.WhenAny(resetEvent, Task.Delay(millisecondsDelay, cancellationToken)); | ||
|
||
return task == resetEvent; | ||
} | ||
|
||
public Task<bool> Wait(TimeSpan delay, CancellationToken cancellationToken = default) | ||
{ | ||
return Wait((int)delay.TotalMilliseconds, cancellationToken); | ||
} | ||
|
||
public void Set() | ||
{ | ||
lock (_lock) | ||
{ | ||
var tcs = _tcs; | ||
tcs.TrySetResult(true); | ||
} | ||
} | ||
|
||
public void Reset() | ||
{ | ||
lock (_lock) | ||
{ | ||
if (_tcs.Task.IsCompleted) | ||
{ | ||
_tcs = new TaskCompletionSource<bool>(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace SlimMessageBus.Host.Outbox.Services; | ||
|
||
public interface IOutboxNotificationService | ||
{ | ||
/// <summary> | ||
/// Notify outbox service that a message is waiting to be published. | ||
/// </summary> | ||
void Notify(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...us.Host.Outbox/IOutboxLockRenewalTimer.cs → ...utbox/Services/IOutboxLockRenewalTimer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
....Outbox/IOutboxLockRenewalTimerFactory.cs → ...ervices/IOutboxLockRenewalTimerFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace SlimMessageBus.Host.Outbox; | ||
namespace SlimMessageBus.Host.Outbox.Services; | ||
|
||
using System.Threading; | ||
|
||
|
5 changes: 3 additions & 2 deletions
5
...Bus.Host.Outbox/OutboxLockRenewalTimer.cs → ...Outbox/Services/OutboxLockRenewalTimer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...t.Outbox/OutboxLockRenewalTimerFactory.cs → ...Services/OutboxLockRenewalTimerFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.