MCPcopy Create free account
hub / github.com/Permify/permify / checkRun

Function checkRun

internal/engines/check.go:820–862  ·  view source on GitHub ↗

checkRun is a function that executes a list of CheckFunctions concurrently with a specified limit.

(ctx context.Context, functions []CheckFunction, decisionChan chan<- CheckResponse, limit int)

Source from the content-addressed store, hash-verified

818
819// checkRun is a function that executes a list of CheckFunctions concurrently with a specified limit.
820func checkRun(ctx context.Context, functions []CheckFunction, decisionChan chan<- CheckResponse, limit int) func() {
821 // Create a channel that enforces the concurrency limit
822 cl := make(chan struct{}, limit)
823 var wg sync.WaitGroup
824
825 // Define a helper function that calls a CheckFunction and sends the result to the decisionChan
826 check := func(child CheckFunction) {
827 result, err := child(ctx)
828 decisionChan <- CheckResponse{
829 resp: result,
830 err: err,
831 }
832 // Once the CheckFunction is done, release the concurrency limit
833 <-cl
834 wg.Done()
835 }
836
837 // Start a goroutine that iterates over the functions
838 wg.Add(1)
839 go func() {
840 run:
841 // Iterate over the functions
842 for _, fun := range functions {
843 child := fun
844 select {
845 // If the concurrency limit allows it, start the function in a new goroutine
846 case cl <- struct{}{}:
847 wg.Add(1)
848 go check(child)
849 // If the context is done, break the loop
850 case <-ctx.Done():
851 break run
852 }
853 }
854 wg.Done()
855 }()
856
857 // Return a cleanup function that waits for all goroutines to finish and then closes the concurrency limit channel
858 return func() {
859 wg.Wait()
860 close(cl)
861 }
862}
863
864// checkFail is a helper function that returns a CheckFunction that always returns a denied PermissionCheckResponse
865// with the provided error and an empty PermissionCheckResponseMetadata.

Callers 3

checkUnionFunction · 0.85
checkIntersectionFunction · 0.85
checkExclusionFunction · 0.85

Calls 4

closeFunction · 0.85
checkStruct · 0.70
WaitMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected