Created
April 9, 2023 13:31
-
-
Save fabiante/b87e2fcf4107f46a8e7c61bf5078fe40 to your computer and use it in GitHub Desktop.
MS Graph SDK Go Client Lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ms | |
import ( | |
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | |
msgraphsdkgo "github.com/microsoftgraph/msgraph-sdk-go" | |
"sync" | |
) | |
// graphServiceClientFactoryLock is used to ensure that only one instance of any msgraphsdkgo.GraphServiceClient | |
// is created at a time. This is necessary because the standard constructor functions do not seem to be thread safe. | |
var graphServiceClientFactoryLock sync.Mutex | |
// NewGraphServiceClientWithCredentials | |
// | |
// See graphServiceClientFactoryLock on why this function exists. | |
func NewGraphServiceClientWithCredentials(credential azcore.TokenCredential, scopes []string) (*msgraphsdkgo.GraphServiceClient, error) { | |
graphServiceClientFactoryLock.Lock() | |
defer graphServiceClientFactoryLock.Unlock() | |
return msgraphsdkgo.NewGraphServiceClientWithCredentials(credential, scopes) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment