Skip to content

Commit

Permalink
Fix linter, add .editorconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
zenthangplus committed Aug 20, 2022
1 parent ea06bcf commit 45bca4a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand Down
14 changes: 7 additions & 7 deletions goccm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
}
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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
}

0 comments on commit 45bca4a

Please sign in to comment.