Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(async): change worker gr lifetime (#4) #9

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,32 @@
"exportloopref",
"extendio",
"fieldalignment",
"gobby",
"goconst",
"gocritic",
"gocyclo",
"gofmt",
"goimports",
"goleak",
"gomnd",
"gosec",
"gosimple",
"govet",
"graffico",
"ineffassign",
"jibberjabber",
"leaktest",
"linters",
"lorax",
"nakedret",
"nolint",
"nolintlint",
"pixa",
"prealloc",
"repotoken",
"sidewalk",
"skeletor",
"smaug",
"staticcheck",
"structcheck",
"stylecheck",
Expand All @@ -45,6 +52,7 @@
"unparam",
"varcheck",
"watchvc",
"watchvi"
"watchvi",
"xenomorph"
]
}
13 changes: 7 additions & 6 deletions async/pool-defs-internal.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package async

type workerInfo[I, R any] struct {
job Job[I]
resultsOut ResultStreamOut[R]
finishedOut FinishedStreamOut
}

const (
// TODO: This is just temporary, channel size definition still needs to be
// fine tuned
//
DefaultChSize = 100
)

type workerWrapper[I any, R any] struct {
cancelChOut chan<- CancelWorkSignal
core *worker[I, R]
}

type workersCollection[I, R any] map[WorkerID]*workerWrapper[I, R]
10 changes: 10 additions & 0 deletions async/pool-defs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package async

const (
MaxWorkers = 100
)

// Job, this definition is very rudimentary and bears no resemblance to the final
// version. The job definition should be data driven not functionally driven. We
// could have a bind function/method that would bind data to the job fn.
Expand All @@ -11,6 +15,7 @@ package async
//

type Job[I any] struct {
ID string
Input I
}

Expand Down Expand Up @@ -39,3 +44,8 @@ type WorkerID string
type FinishedStream = chan WorkerID
type FinishedStreamIn = <-chan WorkerID
type FinishedStreamOut = chan<- WorkerID

// joinChannelsFunc allows reader channel to be joined to the writer channel. This
// function is called when entry is found on the input and forwarded to the
// output.
type JoinChannelsFunc[T any] func(inCh <-chan T, outCh chan<- T)
Loading