From 45bca4a6256763899d1bb084782f4d698fd5e789 Mon Sep 17 00:00:00 2001 From: Thang Bui Date: Sat, 20 Aug 2022 22:33:14 +0700 Subject: [PATCH] Fix linter, add .editorconfig --- .editorconfig | 18 ++++++++++++++++++ README.md | 24 ++++++++++++------------ goccm.go | 14 +++++++------- 3 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c49f56c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +indent_style = tab +indent_size = 4 +tab_width = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{md,apib}] +indent_style = space + +[*.{xml,yaml,yml,json}] +indent_style = space +indent_size = 2 +tab_width = 2 diff --git a/README.md b/README.md index 5a20cac..7258385 100644 --- a/README.md +++ b/README.md @@ -25,26 +25,26 @@ import ( "time" ) -func main() { +func main() { // Limit 3 goroutines to run concurrently. c := goccm.New(3) - + for i := 1; i <= 10; i++ { - + // This function has to call before any goroutine c.Wait() - + go func(i int) { fmt.Printf("Job %d is running\n", i) time.Sleep(2 * time.Second) - + // This function has to when a goroutine has finished // Or you can use `defer c.Done()` at the top of goroutine. c.Done() }(i) } - - // This function has to call to ensure all goroutines have finished + + // This function has to call to ensure all goroutines have finished // after close the main program. c.WaitAllDone() } @@ -61,19 +61,19 @@ func main() { // Create the concurrency manager // The first argument is the maximum number of goroutines to run concurrently. c := goccm.New(10) - + // Wait until a slot is available for the new goroutine. c.Wait() - + // Mark a goroutine as finished c.Done() - + // Wait for all goroutines are done c.WaitAllDone() - + // Close the manager manually c.Close() - + // Returns the number of goroutines which are running c.RunningCount() } diff --git a/goccm.go b/goccm.go index 3cf5ff6..737e700 100644 --- a/goccm.go +++ b/goccm.go @@ -8,16 +8,16 @@ type ( // Wait until a slot is available for the new goroutine. Wait() - // Mark a goroutine as finished + // Done Mark a goroutine as finished Done() // Close the manager manually Close() - // Wait for all goroutines are done + // WaitAllDone Wait for all goroutines are done WaitAllDone() - // Returns the number of goroutines which are running + // RunningCount Returns the number of goroutines which are running RunningCount() int32 } @@ -75,7 +75,7 @@ func (c *concurrencyManager) controller() { // When the closed flag is set, // we need to close the manager if it doesn't have any running goroutine - if c.closed == true && c.runningCount == 0 { + if c.closed && c.runningCount == 0 { break } } @@ -97,7 +97,7 @@ func (c *concurrencyManager) Wait() { atomic.AddInt32(&c.runningCount, 1) } -// Mark a goroutine as finished +// Done Mark a goroutine as finished func (c *concurrencyManager) Done() { // Decrease the number of running count atomic.AddInt32(&c.runningCount, -1) @@ -109,7 +109,7 @@ func (c *concurrencyManager) Close() { c.closed = true } -// Wait for all goroutines are done +// WaitAllDone Wait for all goroutines are done func (c *concurrencyManager) WaitAllDone() { // Close the manager automatic c.Close() @@ -118,7 +118,7 @@ func (c *concurrencyManager) WaitAllDone() { <-c.allDoneCh } -// Returns the number of goroutines which are running +// RunningCount Returns the number of goroutines which are running func (c *concurrencyManager) RunningCount() int32 { return c.runningCount }