Junior — Middle
Describe how workflows were built and managed in your previous organization.
sobes.tech AI
Answer from AI
In the previous organization, workflows were built using goroutines and channels in Go for efficient management of parallel tasks.
Main points:
- Each task was launched in a separate goroutine, allowing multiple processes to run simultaneously.
- Channels were used for synchronization and data transfer between goroutines, ensuring safe information exchange.
- A
sync.WaitGroupwas used to wait for all goroutines to finish.
Example:
var wg sync.WaitGroup
jobs := make(chan int, 10)
worker := func(id int, jobs <-chan int, wg *sync.WaitGroup) {
defer wg.Done()
for job := range jobs {
fmt.Printf("Worker %d processing job %d\n", id, job)
// task processing
}
}
func main() {
for w := 1; w <= 3; w++ {
wg.Add(1)
go worker(w, jobs, &wg)
}
for j := 1; j <= 5; j++ {
jobs <- j
}
close(jobs)
wg.Wait()
}
Thus, the processes were organized as a pool of workers that processed incoming tasks in parallel.