feat: add basic worker pool

This commit is contained in:
Alexander Navarro 2024-11-26 15:44:08 -03:00
parent d1a0212cb1
commit 56d2e72528
3 changed files with 144 additions and 12 deletions

View file

@ -1,6 +1,9 @@
package synchronizator
import "slices"
import (
"fmt"
"slices"
)
// Utility struct to represent a collection of nodes, it's a [Node] itself so all
// the node's functionality is available.
@ -10,6 +13,26 @@ type Platform struct {
}
func (platform *Platform) FetchCollections(fetcher Fetcher, start_pagination Pagination) error {
square := func(value int) int {
return value * value
}
manager := createWorkerPool[int](5, square)
err := manager.AddWork(5)
if err != nil {
return err
}
for value := range manager.GetWorkUnit() {
fmt.Printf("%v: Concurrent value: %v \n", start_pagination.Offset, value)
}
err = manager.AddWork(45)
if err != nil {
return err
}
collections, pagination, err := fetcher(start_pagination)
if err != nil {
return err