mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-03-24 20:08:08 +00:00
* simv2: wip * simulation: exec adapter start/stop * simulation: add node status to exec adapter * simulation: initial simulation code * simulation: exec adapter, configure path to executable * simulation: initial docker adapter * simulation: wip kubernetes adapter * simulation: kubernetes adapter proxy * simulation: implement GetAll/StartAll/StopAll * simulation: kuberentes adapter - set env vars and resource limits * simulation: discovery test * simulation: remove port definitions within docker adapter * simulation: simplify wait for healthy loop * simulation: get nat ip addr from interface * simulation: pull docker images automatically * simulation: NodeStatus -> NodeInfo * simulation: move discovery test to example dir * simulation: example snapshot usage * simulation: add goclient specific simulation * simulation: add peer connections to snapshot * simulation: close rpc client * simulation: don't export kubernetes proxy server * simulation: merge simulation code * simulation: don't export nodemap * simulation: rename SimulationSnapshot -> Snapshot * simulation: linting fixes * simulation: add k8s available helper func * simulation: vendor * simulation: fix 'no non-test Go files' when building * simulation: remove errors from interface methods where non were returned * simulation: run getHealthInfo check in parallel
49 lines
No EOL
1.8 KiB
Markdown
49 lines
No EOL
1.8 KiB
Markdown
# concurrent
|
|
|
|
[](https://sourcegraph.com/github.com/modern-go/concurrent?badge)
|
|
[](http://godoc.org/github.com/modern-go/concurrent)
|
|
[](https://travis-ci.org/modern-go/concurrent)
|
|
[](https://codecov.io/gh/modern-go/concurrent)
|
|
[](https://goreportcard.com/report/github.com/modern-go/concurrent)
|
|
[](https://raw.githubusercontent.com/modern-go/concurrent/master/LICENSE)
|
|
|
|
* concurrent.Map: backport sync.Map for go below 1.9
|
|
* concurrent.Executor: goroutine with explicit ownership and cancellable
|
|
|
|
# concurrent.Map
|
|
|
|
because sync.Map is only available in go 1.9, we can use concurrent.Map to make code portable
|
|
|
|
```go
|
|
m := concurrent.NewMap()
|
|
m.Store("hello", "world")
|
|
elem, found := m.Load("hello")
|
|
// elem will be "world"
|
|
// found will be true
|
|
```
|
|
|
|
# concurrent.Executor
|
|
|
|
```go
|
|
executor := concurrent.NewUnboundedExecutor()
|
|
executor.Go(func(ctx context.Context) {
|
|
everyMillisecond := time.NewTicker(time.Millisecond)
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
fmt.Println("goroutine exited")
|
|
return
|
|
case <-everyMillisecond.C:
|
|
// do something
|
|
}
|
|
}
|
|
})
|
|
time.Sleep(time.Second)
|
|
executor.StopAndWaitForever()
|
|
fmt.Println("executor stopped")
|
|
```
|
|
|
|
attach goroutine to executor instance, so that we can
|
|
|
|
* cancel it by stop the executor with Stop/StopAndWait/StopAndWaitForever
|
|
* handle panic by callback: the default behavior will no longer crash your application |