Go: introducing SHM_ACK observer.
Each request processed in a separate goroutine. In case of OOSM state, during response write, request goroutine blocks on channel which waits event from main thread about SHM_ACK message from router.
This commit is contained in:
32
go/observable.go
Normal file
32
go/observable.go
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) NGINX, Inc.
|
||||
*/
|
||||
|
||||
package unit
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type observable struct {
|
||||
sync.Mutex
|
||||
observers []chan int
|
||||
}
|
||||
|
||||
func (o *observable) attach(c chan int) {
|
||||
o.Lock()
|
||||
defer o.Unlock()
|
||||
|
||||
o.observers = append(o.observers, c)
|
||||
}
|
||||
|
||||
func (o *observable) notify(e int) {
|
||||
o.Lock()
|
||||
defer o.Unlock()
|
||||
|
||||
for _, v := range o.observers {
|
||||
v <- e
|
||||
}
|
||||
|
||||
o.observers = nil
|
||||
}
|
||||
Reference in New Issue
Block a user