File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,24 @@ func (s *Server) Publish(id string, event *Event) {
122122 }
123123}
124124
125+ // TryPublish is the same as Publish except that when the operation would cause
126+ // the call to be blocked, it simply drops the message and returns false.
127+ // Together with a small BufferSize, it can be useful when publishing the
128+ // latest message ASAP is more important than reliable delivery.
129+ func (s * Server ) TryPublish (id string , event * Event ) bool {
130+ stream := s .getStream (id )
131+ if stream == nil {
132+ return false
133+ }
134+
135+ select {
136+ case stream .event <- s .process (event ):
137+ return true
138+ default :
139+ return false
140+ }
141+ }
142+
125143func (s * Server ) getStream (id string ) * Stream {
126144 s .muStreams .RLock ()
127145 defer s .muStreams .RUnlock ()
You can’t perform that action at this time.
0 commit comments