mirror of
https://github.com/libp2p/go-libp2p-resource-manager.git
synced 2025-03-10 17:20:39 +08:00
implement scope viewers
This commit is contained in:
parent
3422b8cbde
commit
71b70cd48b
26
rcmgr.go
26
rcmgr.go
@ -123,24 +123,30 @@ func NewResourceManager(limits Limiter) *ResourceManager {
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *ResourceManager) GetSystem() network.ResourceScope {
|
||||
return r.system
|
||||
func (r *ResourceManager) ViewSystem(f func(network.ResourceScope) error) error {
|
||||
return f(r.system)
|
||||
}
|
||||
|
||||
func (r *ResourceManager) GetTransient() network.ResourceScope {
|
||||
return r.transient
|
||||
func (r *ResourceManager) ViewTransient(f func(network.ResourceScope) error) error {
|
||||
return f(r.transient)
|
||||
}
|
||||
|
||||
func (r *ResourceManager) GetService(srv string) network.ServiceScope {
|
||||
return r.getServiceScope(srv)
|
||||
func (r *ResourceManager) ViewService(srv string, f func(network.ServiceScope) error) error {
|
||||
return f(r.getServiceScope(srv))
|
||||
}
|
||||
|
||||
func (r *ResourceManager) GetProtocol(proto protocol.ID) network.ProtocolScope {
|
||||
return r.getProtocolScope(proto)
|
||||
func (r *ResourceManager) ViewProtocol(proto protocol.ID, f func(network.ProtocolScope) error) error {
|
||||
s := r.getProtocol(proto)
|
||||
defer s.DecRef()
|
||||
|
||||
return f(s)
|
||||
}
|
||||
|
||||
func (r *ResourceManager) GetPeer(p peer.ID) network.PeerScope {
|
||||
return r.getPeerScope(p)
|
||||
func (r *ResourceManager) ViewPeer(p peer.ID, f func(network.PeerScope) error) error {
|
||||
s := r.getPeerScope(p)
|
||||
defer s.DecRef()
|
||||
|
||||
return f(s)
|
||||
}
|
||||
|
||||
func (r *ResourceManager) getServiceScope(svc string) *ServiceScope {
|
||||
|
Loading…
Reference in New Issue
Block a user