A lot has been said on argument of event-based loop, achieving parallelism and difference between Thread
and Task<T>
.
I'd like to quote
What is the difference between task and thread?
that clearly explains how a Task<T>
is a promise and the thread could be one of the means used to fulfil it.
This other question instead address the first point of the introduction
Here come the question. I'm figuring how to design a reusable .NET infrastructural type(s) that can invoke a delegate when a particular event occur. Off course I've evaluated all reference supplied by the second question, but I feel that I still need to investigate more.
I'd like to achieve something like:
var sched = new Scheduler(new DefaultSchedulingStrategy());
var listnr = new TcpListener();
sched.DefineEventSource<Socket>(listnr.AcceptSocketAsync);
shed.OnEvent(
(socket) = {
// handling socket here
});
I know that this seems very close to Task.Factory.FromAsync<T>
. Anyway what I want to achieve here is also being able to change the scheduling strategy on different workloads and try to abstract as much as possible the logic that activates the event.
I've also considered writing a bare bone scheduler in F# (e.g. based on agents), create a C#-friendly reusable library and than code the rest of the server in C# (as it's my primary development language for the moment).
I hope I was clear enough (sorry but English is not my primary language).