mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-07 15:23:08 +00:00
feat: new WithMsgIdFunction topic option to enable topics to have own msg id generation rules
This commit is contained in:
parent
0e687f24a6
commit
6035642336
@ -1160,6 +1160,14 @@ type TopicOptions struct{}
|
|||||||
|
|
||||||
type TopicOpt func(t *Topic) error
|
type TopicOpt func(t *Topic) error
|
||||||
|
|
||||||
|
// WithMsgIdFunction sets custom MsgIdFunction for a Topic, enabling topics to have own msg id generation rules.
|
||||||
|
func (p *PubSub) WithMsgIdFunction(msgId MsgIdFunction) TopicOpt {
|
||||||
|
return func(t *Topic) error {
|
||||||
|
t.p.idGen.Set(t.topic, msgId)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Join joins the topic and returns a Topic handle. Only one Topic handle should exist per topic, and Join will error if
|
// Join joins the topic and returns a Topic handle. Only one Topic handle should exist per topic, and Join will error if
|
||||||
// the Topic handle already exists.
|
// the Topic handle already exists.
|
||||||
func (p *PubSub) Join(topic string, opts ...TopicOpt) (*Topic, error) {
|
func (p *PubSub) Join(topic string, opts ...TopicOpt) (*Topic, error) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user