PrimaShouji / Prima2

The Discord bot.
Apache License 2.0
0 stars 4 forks source link

Convert Task-based continuous services into Thread-based ones #3

Open karashiiro opened 3 years ago

karashiiro commented 3 years ago

Tasks are made for one-off actions. They are not made for continuously-running ones, because Tasks have no guarantees of when they will actually be executed. This problem is only exacerbated when the Tasks hog the underlying thread pool. This has been an issue during testing -- in loops where logging doesn't happen immediately, the loops rarely don't run.

or

STOP USING TaskS

LOOK at what Programmers have been demanding your Respect for all this time, with all the programming languages & concurrency primitives we built for them

(This is REAL Programming, done by REAL Programmers):

while (!token.IsCancellationRequested) 
{
    // ?????
}
while (true) 
{
    if (token.IsCancellationRequested)
        token.ThrowIfCancellationRequested();
    // ???????
}
while (!done)
{
    // ?????????????????
    if (token.IsCancellationRequested) throw new OperationCanceledException();
    await Task.WhenAll(_db.Users.Select(u => _client.GetUser(u.DiscordId)).Select(async user => await user.AddRoleAsync(guild.Roles.FirstOrDefault(r => r.Name == "tasks for brains"))));
    await Task.Delay(new TimeSpan(1, 0, 0));
}

They have played us for absolute fools

karashiiro commented 2 years ago

Memes aside, I'll just migrate to Quartz for this. I can use this for the announcement system as well, to clean it up a bit more.