Skip to content

Commit

Permalink
feat: add example
Browse files Browse the repository at this point in the history
  • Loading branch information
mehditeymorian committed Jun 22, 2022
1 parent 1cf3243 commit 88e264b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions example/printer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"log"
"time"

"github.com/mehditeymorian/koi"
)

func main() {
pond := koi.NewPond()

printWorker := koi.Worker{
ConcurrentCount: 2,
QueueSize: 10,
Work: func(a any) any {
time.Sleep(1 * time.Second)
log.Println(a)

return nil
},
}

_ = pond.RegisterWorker("printer", printWorker)

for i := 0; i < 10; i++ {
_, err := pond.AddJob("printer", i)
if err != nil {
log.Printf("error while adding job: %v\n", err)
}
}

log.Println("all job added")

for {

}
}

0 comments on commit 88e264b

Please sign in to comment.