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

Fixes using setTimeout/setInterval in a Android Worker #2931

Merged
merged 1 commit into from
Oct 20, 2016
Merged

Fixes using setTimeout/setInterval in a Android Worker #2931

merged 1 commit into from
Oct 20, 2016

Conversation

NathanaelA
Copy link
Contributor

The current setTimeout code for android uses getMainLooper() which will cause the worker timer to fire on the main thread. The code needs to actually run on the correct thread that started it; switching to "myLooper" will work on both the main thread and on worker threads.

To duplicate:
app.js

var x =new Worker('timer.js');
setTimeout(function() { console.log("Main thread worked"); }, 100);

timer.js

require('globals');
setTimeout(function() { console.log("Worker Worked"); }, 100);

Will produce on unfixed core modules:

An uncaught Exception occurred on "main" thread.
com.tns.NativeScriptException: Cannot find object id for instance=com.tns.gen.java.lang.Runnable@52a37664
at com.tns.Runtime.callJSMethodImpl(Runtime.java:889)
at com.tns.Runtime.callJSMethod(Runtime.java:883)
at com.tns.Runtime.callJSMethod(Runtime.java:867)
at com.tns.Runtime.callJSMethod(Runtime.java:859)
at com.tns.gen.java.lang.Runnable.run(java.lang.Runnable.java)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

@ns-bot
Copy link

ns-bot commented Oct 20, 2016

Can one of the admins verify this patch?

@enchev
Copy link
Contributor

enchev commented Oct 20, 2016

run ci

@enchev enchev merged commit ffc611c into NativeScript:master Oct 20, 2016
@lock
Copy link

lock bot commented Aug 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Aug 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants