moved options into their own file and more tests
This commit is contained in:
14
options.go
14
options.go
@@ -1,23 +1,29 @@
|
||||
package gubgub
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// TopicOptions holds common options for topics.
|
||||
type TopicOptions struct {
|
||||
// onClose is called after the Topic is closed and all messages have been delivered.
|
||||
// onClose is called after the Topic is closed and all messages have been delivered. Even
|
||||
// though you might call Close multiple times, topics are effectively closed only once thus
|
||||
// this should be called only once.
|
||||
onClose func()
|
||||
|
||||
// onSubscribe is called after a new subscriber is regitered.
|
||||
onSubscribe func(count int)
|
||||
onSubscribe func()
|
||||
}
|
||||
|
||||
type TopicOption func(*TopicOptions)
|
||||
|
||||
func WithOnClose(fn func()) TopicOption {
|
||||
return func(opts *TopicOptions) {
|
||||
opts.onClose = fn
|
||||
opts.onClose = sync.OnceFunc(fn)
|
||||
}
|
||||
}
|
||||
|
||||
func WithOnSubscribe(fn func(count int)) TopicOption {
|
||||
func WithOnSubscribe(fn func()) TopicOption {
|
||||
return func(opts *TopicOptions) {
|
||||
opts.onSubscribe = fn
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user