major refactor to accommodate feed

This commit is contained in:
2024-09-09 11:22:00 +01:00
parent 4741acc016
commit a394dab041
9 changed files with 360 additions and 223 deletions

24
options.go Normal file
View File

@@ -0,0 +1,24 @@
package gubgub
// TopicOptions holds common options for topics.
type TopicOptions struct {
// onClose is called after the Topic is closed and all messages have been delivered.
onClose func()
// onSubscribe is called after a new subscriber is regitered.
onSubscribe func(count int)
}
type TopicOption func(*TopicOptions)
func WithOnClose(fn func()) TopicOption {
return func(opts *TopicOptions) {
opts.onClose = fn
}
}
func WithOnSubscribe(fn func(count int)) TopicOption {
return func(opts *TopicOptions) {
opts.onSubscribe = fn
}
}