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:
Max Romanov
2019-12-24 18:04:21 +03:00
parent 763bdff401
commit 26ee4cb6c8
3 changed files with 77 additions and 11 deletions

32
go/observable.go Normal file
View 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
}