Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tirumalesh-yeligar-by committed Aug 1, 2021
0 parents commit dac3a6f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/TaskPool.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"fmt"
"time"
)

func PrintPayload(payload map[string]string) {
time.Sleep(time.Second)
fmt.Println(payload)
}
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"TaskPool/worker"
"time"
)

func main() {
defer worker.Wait()
for i :=0; i < 10000000; i++ {
job := worker.Job{
Action: PrintPayload,
Payload: map[string]string{
"time": time.Now().String(),
},
}
job.Fire()
}

time.Sleep(time.Second * 3)
}
25 changes: 25 additions & 0 deletions worker/worker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package worker

import "sync"

var wg sync.WaitGroup

type Job struct {
id string
Action func(map[string]string)
Payload map[string]string
}

func Wait() {
wg.Wait()
}

func (job Job) Fire() {
wg.Add(1)

go func() {
defer wg.Done()
job.Action(job.Payload)
}()

}

0 comments on commit dac3a6f

Please sign in to comment.