Our first example demonstrates the use of a TaskGroup, which is similar to a wait group. It allows us to wait for multiple tasks to finish.
To run the program, save it as taskgroups.d and use the D compiler:
The order of workers starting up and finishing is likely to be different for each invocation.
In this D version, we use a TaskGroup instead of a WaitGroup. The TaskGroup in D serves a similar purpose, allowing us to create and manage multiple concurrent tasks. We create tasks using tg.create() instead of launching goroutines, and we use tg.wait() to wait for all tasks to complete, similar to wg.Wait() in Go.
The worker function remains largely the same, but we use D’s writefln for formatted output and Thread.sleep for simulating work.
Note that D’s concurrency model is different from Go’s, but this example demonstrates a similar concept of managing multiple concurrent tasks and waiting for their completion.