init
This commit is contained in:
47
figures/figure-1.go
Normal file
47
figures/figure-1.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// BASIC OMIT
|
||||
|
||||
func finishReq(timeout time.Duration) r ob {
|
||||
- ch := make(chan ob) // HL
|
||||
+ ch := make(chan ob, 1) // HL
|
||||
go func() {
|
||||
result := fn()
|
||||
ch <- result // block
|
||||
}()
|
||||
select {
|
||||
case result = <- ch:
|
||||
return result
|
||||
case <- time.After(timeout):
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ENDBASIC OMIT
|
||||
|
||||
// FULL OMIT
|
||||
|
||||
func finishRequest(timeout time.Duration, fn resultFunc) (result runtime.Object, err error) {
|
||||
- ch := make(chan runtime.Object) // HL
|
||||
- errCh := make(chan error) // HL
|
||||
+ ch := make(chan runtime.Object, 1) // HL
|
||||
+ errCh := make(chan error, 1) // HL
|
||||
go func() {
|
||||
if result, err := fn(); err != nil {
|
||||
errCh <- err
|
||||
} else {
|
||||
ch <- result
|
||||
}
|
||||
}()
|
||||
select {
|
||||
case result = <-ch:
|
||||
if status, ok := result.(*api.Status); ok {
|
||||
return nil, errors.FromObject(status)
|
||||
}
|
||||
return result, nil
|
||||
case err = <-errCh:
|
||||
return nil, err
|
||||
case <-time.After(timeout):
|
||||
return nil, errors.NewTimeoutError("request did not complete within allowed duration")
|
||||
}
|
||||
}
|
||||
|
||||
// ENDFULL OMIT
|
BIN
figures/figure-2.png
Normal file
BIN
figures/figure-2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 158 KiB |
24
figures/figure-5.go
Normal file
24
figures/figure-5.go
Normal file
@@ -0,0 +1,24 @@
|
||||
var group sync.WaitGroup
|
||||
group.Add(len(pm.plugins))
|
||||
for _, p := range pm.plugins {
|
||||
go func(p *plugin) {
|
||||
defer group.Done()
|
||||
if err := pm.restorePlugin(p); err != nil {
|
||||
logrus.Errorf("Error restoring plugin '%s': %s", p.Name(), err)
|
||||
return
|
||||
}
|
||||
pm.Lock()
|
||||
pm.nameToID[p.Name()] = p.PluginObj.ID
|
||||
requiresManualRestore := !pm.liveRestore && p.PluginObj.Active
|
||||
pm.Unlock()
|
||||
if requiresManualRestore {
|
||||
// if liveRestore is not enabled, the plugin will be stopped now so we should enable it
|
||||
if err := pm.enable(p); err != nil {
|
||||
logrus.Errorf("Error enabling plugin '%s': %s", p.Name(), err)
|
||||
}
|
||||
}
|
||||
}(p)
|
||||
- group.Wait() // HL
|
||||
}
|
||||
+ group.Wait() // HL
|
||||
return pm.save()
|
9
figures/figure-6.go
Normal file
9
figures/figure-6.go
Normal file
@@ -0,0 +1,9 @@
|
||||
- hctx, hcancel := context.WithCancel(ctx) // HL
|
||||
+ var hctx context.Context // HL
|
||||
+ var hcancel context.CancelFunc // HL
|
||||
if c.headerTimeout > 0 {
|
||||
hctx, hcancel = context.WithTimeout(ctx, c.headerTimeout)
|
||||
+ } else { // HL
|
||||
+ hctx, hcancel = context.WithCancel(ctx) // HL
|
||||
}
|
||||
defer hcancel()
|
17
figures/figure-7.go
Normal file
17
figures/figure-7.go
Normal file
@@ -0,0 +1,17 @@
|
||||
func goroutine1() {
|
||||
m.Lock()
|
||||
- ch <- request //blocks // HL
|
||||
+ select { // HL
|
||||
+ case ch <- request: // HL
|
||||
+ default: // HL
|
||||
}
|
||||
m.Unlock()
|
||||
}
|
||||
|
||||
func goroutine2() {
|
||||
for {
|
||||
m.Lock() //blocks
|
||||
m.Unlock()
|
||||
request <- ch
|
||||
}
|
||||
}
|
9
figures/figure-8.go
Normal file
9
figures/figure-8.go
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
for i := 17; i <= 21; i++ { // write
|
||||
- go func() { // HL
|
||||
+ go func(i int) { // HL
|
||||
apiVersion := fmt.Sprintf("v1.%d", i)
|
||||
- }() // HL
|
||||
+ }(i) // HL
|
||||
}
|
25
figures/figure-9.go
Normal file
25
figures/figure-9.go
Normal file
@@ -0,0 +1,25 @@
|
||||
func (p *peer) send(d []byte) error {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
switch p.status {
|
||||
case idlePeer:
|
||||
if p.inflight.Get() > maxInflight {
|
||||
return fmt.Errorf("reach max idle")
|
||||
}
|
||||
+ p.wg.Add(1) // HL
|
||||
go func() {
|
||||
- p.wg.Add(1) // HL
|
||||
p.post(d)
|
||||
p.wg.Done()
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
func (p *peer) stop() {
|
||||
p.mu.Lock()
|
||||
if p.status == participantPeer {
|
||||
close(p.queue)
|
||||
}
|
||||
p.status = stoppedPeer
|
||||
p.mu.Unlock()
|
||||
p.wg.Wait()
|
||||
}
|
BIN
figures/table-12.png
Normal file
BIN
figures/table-12.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 85 KiB |
BIN
figures/table-2.png
Normal file
BIN
figures/table-2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 133 KiB |
BIN
figures/table-4.png
Normal file
BIN
figures/table-4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 132 KiB |
BIN
figures/table-5.png
Normal file
BIN
figures/table-5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 102 KiB |
BIN
figures/table-8.png
Normal file
BIN
figures/table-8.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 64 KiB |
Reference in New Issue
Block a user