casbin icon indicating copy to clipboard operation
casbin copied to clipboard

[Question] incomplete method list of SyncedEnforcer

Open JalinWang opened this issue 1 year ago • 4 comments

There are some functions lacking in SyncedEnforcer, i.e., SetAdapter(). I don't think we can always keep them consistent, so can we add a lock-wrapped interface for compatibility? A proof-of-concept:

func (e *SyncedEnforcer) RunSynced(f func()) {
	e.m.Lock()
	defer e.m.Unlock()
	f()
}

//usage

var res [][]string
e.RunSynced(func() {
	e.Enforcer.SetAdapter(a)
	res = e.Enforcer.GetPolicy()
})

More comparision on supported methods: image

JalinWang avatar Jul 26 '22 15:07 JalinWang

@tangyang9464 @JalinWang

casbin-bot avatar Jul 26 '22 15:07 casbin-bot

@JalinWang your method looks interesting. It can be added. But we cannot remove the old way for back compatibility either.

hsluoyz avatar Jul 26 '22 16:07 hsluoyz

@JalinWang I don't see any difference from the previous approach, doesn't this approach also need to deal with each method?

tangyang9464 avatar Jul 27 '22 08:07 tangyang9464

@tangyang9464 e.m is a private member which can't be accessed outside. However, we don't always keep SyncedEnforcer updated with Enforcer, e.g., SetAdapter() is missed in the synced one. I want to provide such a function (or just exposing the internal lock is okay) for users to use the missed method and leave the existing supported methods unchanged.

JalinWang avatar Jul 28 '22 08:07 JalinWang

@JalinWang I think we should always maintain the consistency of the two SyncedEnforcer and Enforcer APIs, instead of providing RunSync, it is not easy to use, and users are prone to misuse

tangyang9464 avatar Aug 11 '22 15:08 tangyang9464

I agree with @tangyang9464 , so closed here for now, we can do offline discussions further if needed

hsluoyz avatar Aug 11 '22 15:08 hsluoyz