dlang / project-ideas

Collection of impactful projects in the D ecosystem
36 stars 12 forks source link

std.parallelism #23

Open burner opened 5 years ago

burner commented 5 years ago

The `std.parallelism` package has been part of Phobos for a while now, and is in production use with many people/applications. Phobos generally has evolved since `std.parallelism` was created and there has been other work on fibers and co-routines in other packages within the D milieu. It would therefore seem a good time to review the tasks system at the heart of `std.parallelism` to see if there are improvements that can be made or general refactorings that are possible. Or it may be that the tasks system just needs some tweaks to improve performance. The issue here is that n active review of `std.parallelism` is due.

shoo commented 3 years ago

std.parallelism is an excellent high-level version of Thread, but it has a few complaints.

  1. It's difficult to specify the type of task when using member variables or managing tasks as arrays.

    Task!Ret[] tasks;
    tasks ~= task(()=>foo());
    tasks ~= task(()=>bar());
  2. I would also like to be able to specify the next process to be performed after the task is completed, like Promise in Javascript. It would also be nice to be able to branch on errors.

    auto t1 = task(()=> foo());
    auto t2 = t1.then( ()=> bar(), () => throw new Exception("foo() failed.") );