-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid multiple refresh #136
Conversation
Do we really need to address concurrency issue in this method? The |
If we think it‘s of great value resolving it in the provider, I would rather like to have a new method something like |
That makes sense. Then this task can simply become to add some details to the API mentioning RefreshTimer, to make sure customers don't have the gap about the behavior. AppConfiguration-JavaScriptProvider/src/AzureAppConfiguration.ts Lines 6 to 10 in 0027254
|
The latest code is much simpler, I like it! |
Why this PR?
The above code snippet simulate the current implementation of refresh and it will produce the following output
The timer fails to prevent refresh operation from being executed multiple times during refresh interval.
Solution
Except for the web worker scenario, javascript is in general single thread. For an async function, it will be synchronously executed until an await occurs, then it will give the control to the event loop. So this should be atomic. So the solution is to maintain a boolean variable
refreshInProgress
to indicate whether there is any ongoing refresh call. The check/setting of the flag will be done synchronously so it should be concurrent/"thread" safe.