Skip to content

Commit

Permalink
Add option to delay to FileStreamNmeaReceiver line yielding (#104)
Browse files Browse the repository at this point in the history
* Add the ability to introduce a delay while yielding the data capture file so that you can throttle data production and not overwhelm the consumer.

* Remove unused fields
  • Loading branch information
HowardvanRooijen authored Mar 24, 2021
1 parent eacca73 commit 88f5211
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ namespace Ais.Net.Receiver.Receiver
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;

public class FileStreamNmeaReceiver : INmeaReceiver
{
private readonly string path;
private readonly TimeSpan delay = TimeSpan.Zero;

public FileStreamNmeaReceiver(string path)
{
this.path = path;
}

public int RetryAttemptLimit { get; }

public TimeSpan RetryPeriodicity { get; }

public FileStreamNmeaReceiver(string path, TimeSpan delay)
{
this.path = path;
this.delay = delay;
}

public async IAsyncEnumerable<string> GetAsync([EnumeratorCancellation] CancellationToken cancellationToken = default)
{
Expand All @@ -34,6 +38,11 @@ public async IAsyncEnumerable<string> GetAsync([EnumeratorCancellation] Cancella
break;
}

if (this.delay > TimeSpan.Zero)
{
await Task.Delay(this.delay, cancellationToken).ConfigureAwait(false);
}

string? line = await sr.ReadLineAsync().ConfigureAwait(false);

if (line is not null) { yield return line; }
Expand Down

0 comments on commit 88f5211

Please sign in to comment.