From ce954dcce67c486dc437c1576046e50823dcf7f4 Mon Sep 17 00:00:00 2001 From: Tejzpr Date: Fri, 12 Mar 2021 08:53:51 -0800 Subject: [PATCH] Updated test case & Readme --- README.md | 18 ++++++++++++++++++ main_test.go | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/README.md b/README.md index ab89ed2..0602798 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/main_test.go b/main_test.go index 6892a19..37556b8 100644 --- a/main_test.go +++ b/main_test.go @@ -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") + }) }