-
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.
- Loading branch information
1 parent
1179130
commit f15758e
Showing
5 changed files
with
9 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
public interface IOffloader<in T> | ||
{ | ||
Task OffloadAsync(T vote); | ||
Task OffloadAsync(T item); | ||
} |
1 change: 1 addition & 0 deletions
1
Source/Offloader/Abstract/OffloadServiceCollectionExtensions.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,5 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Offloader.Implementation; | ||
|
||
namespace Offloader; | ||
|
||
|
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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
using System.Threading.Channels; | ||
|
||
namespace Offloader; | ||
namespace Offloader.Implementation; | ||
|
||
/// <remarks> | ||
/// Should be registered as a singleton. | ||
/// </remarks>> | ||
internal class Offloader<T> : IOffloader<T>, IOffloadReader<T> | ||
{ | ||
private Channel<T> VotesToTranslate { get; } | ||
private Channel<T> OffloadedItems { get; } | ||
= Channel.CreateUnbounded<T>(new UnboundedChannelOptions | ||
{ | ||
SingleReader = true | ||
}); | ||
|
||
public async Task OffloadAsync(T vote) => await VotesToTranslate.Writer.WriteAsync(vote); | ||
public async Task OffloadAsync(T item) => await OffloadedItems.Writer.WriteAsync(item); | ||
|
||
public ChannelReader<T> Reader => VotesToTranslate.Reader; | ||
public ChannelReader<T> Reader => OffloadedItems.Reader; | ||
|
||
public void Complete() => VotesToTranslate.Writer.Complete(); | ||
public void Complete() => OffloadedItems.Writer.Complete(); | ||
} |