diff options
| author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
|---|---|---|
| committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
| commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
| tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/github.com/modern-go/concurrent/README.md | |
| parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
| download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip | |
Make Nix builds work
Diffstat (limited to 'vendor/github.com/modern-go/concurrent/README.md')
| -rw-r--r-- | vendor/github.com/modern-go/concurrent/README.md | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/github.com/modern-go/concurrent/README.md b/vendor/github.com/modern-go/concurrent/README.md new file mode 100644 index 0000000..acab320 --- /dev/null +++ b/vendor/github.com/modern-go/concurrent/README.md | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | # concurrent | ||
| 2 | |||
| 3 | [](https://sourcegraph.com/github.com/modern-go/concurrent?badge) | ||
| 4 | [](http://godoc.org/github.com/modern-go/concurrent) | ||
| 5 | [](https://travis-ci.org/modern-go/concurrent) | ||
| 6 | [](https://codecov.io/gh/modern-go/concurrent) | ||
| 7 | [](https://goreportcard.com/report/github.com/modern-go/concurrent) | ||
| 8 | [](https://raw.githubusercontent.com/modern-go/concurrent/master/LICENSE) | ||
| 9 | |||
| 10 | * concurrent.Map: backport sync.Map for go below 1.9 | ||
| 11 | * concurrent.Executor: goroutine with explicit ownership and cancellable | ||
| 12 | |||
| 13 | # concurrent.Map | ||
| 14 | |||
| 15 | because sync.Map is only available in go 1.9, we can use concurrent.Map to make code portable | ||
| 16 | |||
| 17 | ```go | ||
| 18 | m := concurrent.NewMap() | ||
| 19 | m.Store("hello", "world") | ||
| 20 | elem, found := m.Load("hello") | ||
| 21 | // elem will be "world" | ||
| 22 | // found will be true | ||
| 23 | ``` | ||
| 24 | |||
| 25 | # concurrent.Executor | ||
| 26 | |||
| 27 | ```go | ||
| 28 | executor := concurrent.NewUnboundedExecutor() | ||
| 29 | executor.Go(func(ctx context.Context) { | ||
| 30 | everyMillisecond := time.NewTicker(time.Millisecond) | ||
| 31 | for { | ||
| 32 | select { | ||
| 33 | case <-ctx.Done(): | ||
| 34 | fmt.Println("goroutine exited") | ||
| 35 | return | ||
| 36 | case <-everyMillisecond.C: | ||
| 37 | // do something | ||
| 38 | } | ||
| 39 | } | ||
| 40 | }) | ||
| 41 | time.Sleep(time.Second) | ||
| 42 | executor.StopAndWaitForever() | ||
| 43 | fmt.Println("executor stopped") | ||
| 44 | ``` | ||
| 45 | |||
| 46 | attach goroutine to executor instance, so that we can | ||
| 47 | |||
| 48 | * cancel it by stop the executor with Stop/StopAndWait/StopAndWaitForever | ||
| 49 | * handle panic by callback: the default behavior will no longer crash your application \ No newline at end of file | ||