Skip to content

Commit

Permalink
Long-running tasks using factory
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Jan 10, 2025
1 parent 286aa67 commit 0f86628
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Core/src/Eventuous.Shared/Tools/TaskRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed class TaskRunner(Func<CancellationToken, Task> taskFactory) : IDis
Task? _runner;

public TaskRunner Start() {
_runner = Task.Run(Run);
_runner = Task.Factory.StartNew(Run, _stopSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);

return this;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public ValueTask Write(T element, CancellationToken cancellationToken)
protected ChannelWorkerBase(Channel<T> channel, Func<CancellationToken, Task> processor, int concurrencyLevel, bool throwOnFull = false) {
_channel = channel;
_throwOnFull = throwOnFull;
_readerTasks = Enumerable.Range(0, concurrencyLevel).Select(_ => Task.Run(() => processor(_cts.Token))).ToArray();

_readerTasks = Enumerable.Range(0, concurrencyLevel)
.Select(_ => Task.Factory.StartNew(() => processor(_cts.Token), _cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default))
.ToArray();
}

public async ValueTask DisposeAsync() {
Expand Down

0 comments on commit 0f86628

Please sign in to comment.