Skip to content

Commit

Permalink
feat(async): change worker gr lifetime (#4) (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan authored Aug 11, 2023
1 parent 43c9f9a commit 76521a0
Show file tree
Hide file tree
Showing 10 changed files with 416 additions and 283 deletions.
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

0 comments on commit 76521a0

Please sign in to comment.