diff options
author | Max Romanov <max.romanov@nginx.com> | 2019-12-24 18:04:21 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2019-12-24 18:04:21 +0300 |
commit | 26ee4cb6c8a2248f0f7c99d8c622c86a52bf197a (patch) | |
tree | f17ff41c0fb51de273174c83162d74fc639ef9fd /go/observable.go | |
parent | 763bdff4018ec35de8383273d366160adebb6021 (diff) | |
download | unit-26ee4cb6c8a2248f0f7c99d8c622c86a52bf197a.tar.gz unit-26ee4cb6c8a2248f0f7c99d8c622c86a52bf197a.tar.bz2 |
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.
Diffstat (limited to 'go/observable.go')
-rw-r--r-- | go/observable.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/go/observable.go b/go/observable.go new file mode 100644 index 00000000..9a38802c --- /dev/null +++ b/go/observable.go @@ -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 +} |