MCPcopy
hub / github.com/apache/casbin / StartAutoLoadPolicy

Method StartAutoLoadPolicy

enforcer_synced.go:89–115  ·  view source on GitHub ↗

StartAutoLoadPolicy starts a go routine that will every specified duration call LoadPolicy.

(d time.Duration)

Source from the content-addressed store, hash-verified

87
88// StartAutoLoadPolicy starts a go routine that will every specified duration call LoadPolicy.
89func (e *SyncedEnforcer) StartAutoLoadPolicy(d time.Duration) {
90 // Don't start another goroutine if there is already one running
91 if !atomic.CompareAndSwapInt32(&e.autoLoadRunning, 0, 1) {
92 return
93 }
94
95 ticker := time.NewTicker(d)
96 go func() {
97 defer func() {
98 ticker.Stop()
99 atomic.StoreInt32(&(e.autoLoadRunning), int32(0))
100 }()
101 n := 1
102 for {
103 select {
104 case <-ticker.C:
105 // error intentionally ignored
106 _ = e.LoadPolicy()
107 // Uncomment this line to see when the policy is loaded.
108 // log.Print("Load policy for time: ", n)
109 n++
110 case <-e.stopAutoLoad:
111 return
112 }
113 }
114 }()
115}
116
117// StopAutoLoadPolicy causes the go routine to exit.
118func (e *SyncedEnforcer) StopAutoLoadPolicy() {

Callers 2

TestSyncFunction · 0.95
TestStopAutoLoadPolicyFunction · 0.95

Calls 1

LoadPolicyMethod · 0.95

Tested by 2

TestSyncFunction · 0.76
TestStopAutoLoadPolicyFunction · 0.76