Skip to content

fix: setTimeout does not work on Windows #60

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

Merged
merged 3 commits into from
Oct 3, 2019

Conversation

rosen-vladimirov
Copy link
Contributor

@rosen-vladimirov rosen-vladimirov commented Sep 2, 2019

As the pthread_cancel function is not available on Windows, change the definition of setTimeout method - from now on when you want to use it, you should pass the timeout, the data that you want to be passed to the function that will be executed in case the timeout passes and the function itself.
The setTimeout method automatically allocates memory for the objects, so they will still live even when the function from which you call the setTimeout finishes its execution.
It is not a good idea to capture variables (with lambda functions) when we'll use them in a separate thread. As we do not await the execution of the thread, the captured variables may be cleared (method from which we've called setTimeout finished its execution). More information is available here http://bannalia.blogspot.com/2016/07/passing-capturing-c-lambda-functions-as.html

rosen-vladimirov and others added 2 commits September 2, 2019 23:17
As the pthread_cancel function is not available on Windows, change the definition of setTimeout method - from now on when you want to use it, you should pass the timeout, the data that you want to be passed to the function that will be executed in case the timeout passes and the function itself.
The setTimeout method automatically allocates memory for the objects, so they will still live even when the function from which you call the setTimeout finishes its execution.
It is not a good idea to capture variables (with lambda functions) when we'll use them in a separate thread. As we do not await the execution of the thread, the captured variables may be cleared (method from which we've called setTimeout finished its execution). More information is available here http://bannalia.blogspot.com/2016/07/passing-capturing-c-lambda-functions-as.html
NOTE: Changes are not handled for macOS.
NOTE: Allocated memory should be cleaned in clearTimeout as well.
* clear connection from dictionary when invalidating it
* add mutex while cleaning the connection
@Fatme Fatme force-pushed the vladimirov/settimeout-windows branch from d4be10b to 433515b Compare October 2, 2019 11:54
@Fatme Fatme marked this pull request as ready for review October 2, 2019 11:54
@Fatme Fatme merged commit aef3881 into master Oct 3, 2019
@Fatme Fatme deleted the vladimirov/settimeout-windows branch October 3, 2019 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants