Skip to content

Commit

Permalink
Submit multiple workers at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate North committed Apr 2, 2024
1 parent 8d210e9 commit b4cc0d2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions hive.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ func (hive *Hive) Use(middleFunc ...MiddleFunc) {
hive.middleware = append(hive.middleware, middleFunc...)
}

// Submit starts the worker running and adds it to the hive.
func (hive *Hive) Submit(worker *Worker) {
hive.block.Add(1)
worker.notifyComplete = hive.notifyComplete
worker.middleware = append(hive.middleware, worker.middleware...)
hive.colony = append(hive.colony, worker)
go worker.run(&hive.block)
// Submit starts the workers running and adds them to the hive.
func (hive *Hive) Submit(workers ...*Worker) {
for _, worker := range workers {
hive.block.Add(1)
worker.notifyComplete = hive.notifyComplete
worker.middleware = append(hive.middleware, worker.middleware...)
hive.colony = append(hive.colony, worker)
go worker.run(&hive.block)
}
}

// StopAll should only be used when you are completely done with the hive. Internal channels are
Expand Down

0 comments on commit b4cc0d2

Please sign in to comment.