go-libp2p-pubsub icon indicating copy to clipboard operation
go-libp2p-pubsub copied to clipboard

Allow Topics to close any handles they have

Open aschmahmann opened this issue 5 years ago • 2 comments

@Stebalien mentioned in https://github.com/libp2p/go-libp2p-pubsub-router/pull/37#discussion_r345971256 that the restrictions posed on closing a Topic handle shouldn't need to exist https://github.com/libp2p/go-libp2p-pubsub/blob/01b9825fbee1848751d90a8469e3f5f43bac8466/topic.go#L187

IIUC the reasoning is that since only one valid Topic handle can exist for a given topic that when that handler calls Close() it is willing to kill any existing Subscription or TopicEventHandler objects that are outstanding.

This may clean up some code, by removing a bunch of error checking/handling, but comes at the cost of adding complexity for a Topic with N Subscriptions that only wants to close when all N Subscriptions are closed.

Both options are by me. WDYT @vyzo?

aschmahmann avatar Dec 02 '19 18:12 aschmahmann

Maybe we can simply reference count the closures?

vyzo avatar Dec 02 '19 19:12 vyzo

As we decided in https://github.com/libp2p/go-libp2p-pubsub/issues/198, topic handles are now owned by a single service. There shouldn't be any need to reference count unless I'm missing something.

Stebalien avatar Jan 02 '20 19:01 Stebalien