Skip to content

Commit

Permalink
Merge pull request #2 from falmar/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
falmar committed May 6, 2023
2 parents d3b1de1 + 27a1ced commit aa4bb1e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ func main() {
## License

Krun is released under the MIT License. See [LICENSE](LICENSE) for more information.


## TODO:
- [ ] unit test
- [ ] go releaser
34 changes: 34 additions & 0 deletions examples/basic/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"context"
"fmt"
"math/rand"
"time"

"github.com/falmar/krun"
)

func main() {
random := rand.New(rand.NewSource(time.Now().UnixNano()))
ctx := context.Background()
k := krun.New(krun.NewConfig{
Size: 10,
})

for i := 0; i < 100; i++ {
ctx := context.WithValue(ctx, "key", i)

r := k.Run(ctx, func(ctx context.Context) (interface{}, error) {
// do some work
time.Sleep(time.Millisecond * (300 + time.Duration(random.Intn(700))))
return ctx.Value("key"), nil
})

go func(r <-chan *krun.Result) {
fmt.Println("hello from index:", (<-r).Data)
}(r)
}

k.Wait(context.Background())
}
3 changes: 2 additions & 1 deletion krun.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (k *krun) Run(ctx context.Context, f Job) <-chan *Result {
}

func (k *krun) Wait(ctx context.Context) {
breakL:
for {
select {
case <-ctx.Done():
Expand All @@ -83,7 +84,7 @@ func (k *krun) Wait(ctx context.Context) {
continue
}

break
break breakL
}
}
}
Expand Down

0 comments on commit aa4bb1e

Please sign in to comment.