Skip to content
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

Silent Failure if not called from Main Thread #4

Open
scottcc opened this issue Dec 20, 2017 · 2 comments
Open

Silent Failure if not called from Main Thread #4

scottcc opened this issue Dec 20, 2017 · 2 comments

Comments

@scottcc
Copy link

scottcc commented Dec 20, 2017

It's common practice in Swift to use GCD with a serial queue to replace the @synchronized primitive. Thus, if this is being used from within that code, it won't be on the Main Thread. NSTimer/Timer usage here expects there to be a RunLoop present on the current thread, but that's only generally true of the Main Thread (unless you added one yourself). The current unmodified behaviour when used on a non-Main Thread will be to silently not issue your callback after the delay.

Thus I'd recommend changing this slightly to ensure that if (and only if) not on the Main Thread, the Timer.schedule... call is issued inside a dispatched call with DispatchQueue.main.async {} .

Let me know if you'd support a fork/MR with that, I have one I'm currently using that works for me in this use case.

@webadnan
Copy link
Owner

webadnan commented Dec 20, 2017 via email

@scottcc
Copy link
Author

scottcc commented Dec 22, 2017

Thanks, will do - take a few days but I'll get to it.

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

No branches or pull requests

2 participants