-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚙️ add a collector to the workerpool
This will help us submit as many requests as we want without knowing about the workers. Signed-off-by: Salim Afiune Maya <[email protected]>
- Loading branch information
Showing
5 changed files
with
212 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package workerpool | ||
|
||
type collector[R any] struct { | ||
resultsCh <-chan R | ||
results []R | ||
|
||
errorsCh <-chan error | ||
errors []error | ||
|
||
requestsRead int64 | ||
} | ||
|
||
func (c *collector[R]) Start() { | ||
go func() { | ||
for { | ||
select { | ||
case result := <-c.resultsCh: | ||
c.results = append(c.results, result) | ||
|
||
case err := <-c.errorsCh: | ||
c.errors = append(c.errors, err) | ||
} | ||
|
||
c.requestsRead++ | ||
} | ||
}() | ||
} | ||
|
||
func (c *collector[R]) RequestsRead() int64 { | ||
return c.requestsRead | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.