Conversation
|
@EmperorYP7 can we fix this issue first? #91 |
|
@hsluoyz sure! |
|
Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>
8ee727f to
0875c60
Compare
|
Looks good to me, just one question, if you are going to using this ticker to load policy automatically, do you still want to add a watcher or notify stuff. |
|
@xcaptain I think the // StartAutoLoadPolicy starts a thread that will go through every specified duration call LoadPolicy
void SyncedEnforcer ::StartAutoLoadPolicy(chrono::duration<int64_t, std::nano> t) {
// ...
function<void()> onTick = [this]() {
Enforcer::LoadPolicy();
++n;
};
ticker = unique_ptr<Ticker>(new Ticker(onTick, t));
n = 1;
ticker->start();
}string SyncedEnforcer ::UpdateWrapper() {
LoadPolicy();
return "";
}
// SetWatcher sets the current watcher.
void SyncedEnforcer ::SetWatcher(shared_ptr<Watcher> w){
watcher = w;
return watcher->SetUpdateCallback(&SyncedEnforcer::UpdateWrapper);Although it seems redundant, this will be on par with the API in casbin. So according to me, the ticker should be used exclusively for One more way to implement this is to modify the watcher to utilize ticker and the StartAutoLoadPolicy would rely on this watcher for loading policy asynchronously. |
|
🎉 This PR is included in version 1.14.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |

Signed-off-by: Yash Pandey (YP) yash.btech.cs19@iiitranchi.ac.in
This PR fixes #38
Reference: #89
Description
Most of the functions of SyncedEnforcer are straight-forward to implement but the
AutoLoadPolicyneeded a workaround since it utilized GoLang's ticker from the "time" module and concurrency used here.For this, I created a custom concurrent ticker that takes in the
chrono::durationand afunction<void()>for callback.Ticker::start()will start a loop asynchronously (on a new thread). The parametric function will be called asynchronously as well.Overheads involved:
Apart from the futures obtained from ticker threads, ticker also collects futures from callback at each tick since they're called asynchronously as well. This might lead to a pile of useless data given enough uptime and scope of the Ticker.