http-commands

This commit is contained in:
2023-04-13 20:42:05 +04:00
parent 24c9aa2043
commit e1a9ad476c
31 changed files with 428 additions and 104 deletions
+15 -10
View File
@@ -18,24 +18,29 @@ using System.Threading.Channels;
namespace Ragon.Server.IO;
public class Executor: TaskScheduler, IExecutor
public class Executor : TaskScheduler, IExecutor
{
private ChannelReader<Task> _reader;
private ChannelWriter<Task> _writer;
private Queue<Task> _pendingTasks;
private TaskFactory _taskFactory;
private readonly ChannelReader<Task> _reader;
private readonly ChannelWriter<Task> _writer;
private readonly Queue<Task> _pendingTasks;
private readonly TaskFactory _taskFactory;
public Task Run(Action action)
public Task Run(Action action, TaskCreationOptions task = TaskCreationOptions.None)
{
return _taskFactory.StartNew(action);
return _taskFactory.StartNew(action, task);
}
public Executor()
{
var channel = Channel.CreateUnbounded<Task>();
var channel = Channel.CreateUnbounded<Task>(new UnboundedChannelOptions()
{
SingleReader = true,
SingleWriter = true,
});
_reader = channel.Reader;
_writer = channel.Writer;
_taskFactory = new TaskFactory(this);
_pendingTasks = new Queue<Task>();
}
@@ -60,7 +65,7 @@ public class Executor: TaskScheduler, IExecutor
while (_reader.TryRead(out var task))
{
TryExecuteTask(task);
if (task.Status == TaskStatus.Running)
_pendingTasks.Enqueue(task);
}
+1 -1
View File
@@ -18,5 +18,5 @@ namespace Ragon.Server.IO;
public interface IExecutor
{
public Task Run(Action action);
public Task Run(Action action, TaskCreationOptions task = TaskCreationOptions.None);
}