Skip to content

Commit

Permalink
[API] Provide a default property implementation for IErrorWorker.
Browse files Browse the repository at this point in the history
  • Loading branch information
mandel-macaque committed Sep 5, 2024
1 parent 199910c commit a05b2fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Marille/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ async Task ConsumeChannel<T> (string name, TopicConfiguration configuration, Cha
// the error task in a try/catch to make sure that if the user did raise an exception, we do not
// crash the whole consuming task. Sometimes java was right when adding exceptions to a method signature
try {
if (errorWorker.UseBackgroundThread)
var _ = errorWorker.TryGetUseBackgroundThread (out var useBackgroundThread);
if (useBackgroundThread)
await Task.Run (async () => {
await errorWorker.ConsumeAsync (
item.Payload, item.Exception, cancellationToken).ConfigureAwait (false);
Expand Down
2 changes: 1 addition & 1 deletion src/Marille/IErrorWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IErrorWorker<in T> : IDisposable, IAsyncDisposable where T : st
/// Specifies if the worker should use a background thread to process the messages. If set to
/// true the implementation of the worker should be thread safe.
/// </summary>
public bool UseBackgroundThread { get; }
public bool UseBackgroundThread { get => false; }

/// <summary>
///
Expand Down
11 changes: 11 additions & 0 deletions src/Marille/WorkerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@ public static bool TryGetUseBackgroundThread<T> (this IWorker<T> worker, out boo
return false;
}
}

public static bool TryGetUseBackgroundThread<T> (this IErrorWorker<T> worker, out bool useBackgroundThread) where T : struct
{
useBackgroundThread = false;
try {
useBackgroundThread = worker.UseBackgroundThread;
return true;
} catch {
return false;
}
}
}

0 comments on commit a05b2fb

Please sign in to comment.