Good pattern for reusing job chain.

I’ve implemented an algorithm for parallel weighted random choice, this is a useful thing to have access to from any system, what might a good pattern for this be?

My initial thoughts are to have a static utility class holding all the jobs(about 8 of them), and a public function which is given 2 arrays, one with weights and another for index output. This function returns the final JobHandle which is completed when needed or fed into another job. Is there possibly a better approach?

This is generally good practice and works quite well, especially if that method that does the scheduling also takes a JobHandle as an input.

If you want to get even more fancy, you can use fluent syntax, where the method returns a config object, and then extension methods offer different ways to schedule the jobs. I usually offer RunImmediate (can be called from in job), Run, Schedule, and SheduleParallel.

2 Likes