Skip to content

Commit

Permalink
Updated test case & Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tejzpr committed Mar 12, 2021
1 parent cdcc641 commit ce954dc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ func workFn(val interface{}) interface{} {
}
```
## Run
### Example - 1
```go
func main() {
max := 10
inputChan := make(chan *concurrently.OrderedInput)
output := concurrently.Process(inputChan, workFn, &concurrently.Options{PoolSize: 10, OutChannelBuffer: 10})
go func() {
for work := 0; work < max; work++ {
inputChan <- &concurrently.OrderedInput{work}
}
close(inputChan)
}()
for out := range output {
log.Println(out.Value)
}
}
```
### Example - 2
```go
func main() {
max := 100
Expand Down
23 changes: 23 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,27 @@ func Test(t *testing.T) {
}
t.Log("Test with Default Pool Size and Zero Load Completed")
})
t.Run("Test without workgroup", func(t *testing.T) {
max := 10
inputChan := make(chan *OrderedInput)
output := Process(inputChan, zeroLoadWorkFn, &Options{PoolSize: 10, OutChannelBuffer: 10})
go func() {
for work := 0; work < max; work++ {
inputChan <- &OrderedInput{work}
}
close(inputChan)
}()
counter := 0
for out := range output {
if _, ok := out.Value.(int); !ok {
t.Error("Invalid output")
} else {
counter++
}
}
if counter != max {
t.Error("Input count does not match output count")
}
t.Log("Test without workgroup Completed")
})
}

0 comments on commit ce954dc

Please sign in to comment.