openbullet / openbullet/OpenBullet2
[REQUEST] Add posibility to put back item at the end of the queue in case of unhandled exception in the work Function | RuriLib.Parallelization
@openbullet is already working on this.
Since Jun 10, 2024.
- Dominant language
- C#
- Stars
- 2.4k
- Forks
- 602
- PR merge metrics
- No merged PRs in 30d
Description
Hello, First of all I have to say this library is very useful and works very well.
I came across a problem, let's say I have the following code:
Func<int, CancellationToken, Task<string>> workFunction = new(async (number, token) =>
{
var res = DoSomeWork(number);
if (res == true)
{
// this function can throw an exception in some cases (let's say it is an http request for exemple)
DoSomeOtherWork(number);
return "WhatEver result";
}
else
{
return "WhatEver result";
}
});
var parallelizer = ParallelizerFactory<int, string>.Create(
type: ParallelizerType.TaskBased, // Use task-based (it's better)
workItems: Enumerable.Range(1, 100), // The work items are all integers from 1 to 100
workFunction: workFunction, // Use the work function we defined above
degreeOfParallelism: 5, // Use 5 concurrent tasks at most
totalAmount: 100, // The total amount of tasks you expect to have, used for calculating progress
skip: 0); // How many items to skip from the start of the provided enumerable
parallelizer.TaskError += OnTaskError;
await parallelizer.Start();
In this workFunction when the do DoSomeOtherWork throw an exception it will trigger TaskError event but the item is considered as "completed" and not put back in the queue so if I want to process it I would have to recreate a Parallelizer only with the failed items. this would be easier if there was possibility to put directly back in the queue when the workFunction got an unhandled exception. This feature could be possibly activated or deactivated by a simple parameter in the ctor.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.