-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
Workers API #532
Comments
This comment was marked as abuse.
This comment was marked as abuse.
Also consider researching support for shared array buffers and atomics This is already under a flag in Chrome 48+ |
This comment was marked as abuse.
This comment was marked as abuse.
@NathanaelA while experimenting with the worker API, I too wished that I could pass just a string, but could not. In the end it all boils down to a string, that is compiled in v8; only one has a source, and the other - doesn't, so it should be possible. Can't say yet if it will be in on the end of the first iteration of the WebWorkers support. |
@NathanaelA How does one go about experimenting with the preview channel of the WebWorkers? |
@roblav96 when they are ready, they will be available in the master branch for others to test and experiment with. |
@Pip3r4o So are you saying I can run |
@roblav96 as soon as they make it into the master branch, yes. We will let you know when that is. |
This comment was marked as abuse.
This comment was marked as abuse.
@Pip3r4o Awesome! Thanks so much! How might one go about applying for |
@roblav96 you already have access to 99.9% of what we develop, the Web Workers are still going through internal discussions, architectural planning, and more. We will release a statement very soon with more details on what we have been working on this past month. We are always glad to welcome new contributors. You can begin by becoming familiar with the execution flow of an android application, and the more "advanced" topics in our |
@Pip3r4o Thanks for the heads up. I started my NativeScript endeavour about a month ago and am completely obsessed. I don't consider myself a ninja yet, but I do agree I've come across some things that should be added to the docs. Most importantly how to use android-dts-generator. Am I allowed to to submit a PR to the docs repository? I would like to, but I won't if it will go to waste. |
@roblav96 Absolutely, please do! The submodule android-runtime-docs may be more appropriate for the dts-generator. Also, hit me up in our Community Slack (peter.kanev), and I'll assist you with what I can in my spare time! |
@Pip3r4o Awesome! Sounds great. I look forward to expanding the documentation. Thank you! |
Quick question, would we be able to implement a |
Workers are slowly crawling their way out, I've updated the checklist above to reflect on what has been implemented so far in the android runtime (multithreading branch). Testing is underway, but unit tests alone will not suffice. Do you have any mini scenarios (please be very specific - plugins, work volume?) that you would like to see implemented? One of the tests performs heavy-duty work on a Worker thread, but we need something not so... generic? @NathanaelA @sitefinitysteve |
This comment was marked as abuse.
This comment was marked as abuse.
@NathanaelA The current implementation of the Workers will be available at |
This comment was marked as abuse.
This comment was marked as abuse.
@Pip3r4o |
Work on this issue/story will be resumed as soon as we gather enough feedback for the current state of the Workers |
In your article (http://developer.telerik.com/featured/benefits-single-threading-model-nativescript/), you mentioned:
Does the same applies to the |
@dxshindeo Yes, the current |
Thanks for clearing that up :) |
WEB WORKER IS NOT WORKING IN API17-API19!!! Didn't test API20, but I reccon it also won't work. |
@dxshindeo it would be of great help if you shared what happens on devices of lower API level and what isn't working for you. Thank you! |
Basically, main file:
And worker file:
This works fine in API21+, but in lesser APIs I get only |
@dxshindeo I just tested the above, and it works out well for me, messages are logged properly and communication works back and forth. Tested on Geny Emulator API 17 and native AVD API18 Emulator. Please provide more details like crash logs, or steps to reproduce the behavior you are experiencing. Thanks! |
Hmm now with the above example, sample project Current workaround for me is to wrap that
|
@dxshindeo the implementation of the workers is such that postMessage will execute, and the message on the other end will be received as soon as its thread has finished initializing, so naturally a setTimeout should not be necessary |
Since this issue is about threads, I guess the following question fits here as well - when using |
@dxshindeo I think leaving the calls to the main thread is fairly safe and should not be offloaded to a worker thread. In fact a new thread will likely have a negative impact to the app's available memory if it only deals with the connectivity functionality. |
Big thanks for clearing that up! |
I am using tns 2.5 and postMessage from main thread works fine but the one on the worker thread doesn't work. When on the worker I use the following syntax to post message 'postMessage({src: "test"}, "tempo")'. The extra parameter is a targetOrigin of type string but I got no idea what that is. So the error showing up is "The second parameter of postMessage must be array, null or undefined. If I substitute it with null it still gives me the same error. Not sure what I am doing wrong, can someone help me please. :) |
Ok never mind it seems like the null worked I must have forgot to save it before I run build. |
is there any way to use transferable list as current state? postMessage accepts just 1 argument and throws exception when I provide a transferable list. |
last I checked you can only transfer primitives |
You can transfer objects recursively, but they can only contain primitives. |
Is there any plan to move forward on this? I would love to be able to pass native object. |
@farfromrefug, currently there are some technical limitations which prevent from passing native objects back and forth background workers. As a workaround you could store your native objects into some java dictionary and only pass the key to the worker thread. For example you could define a centralized dictionary: package com.myapp;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public final class WorkersContext {
private final static Map<String, Object> container = new ConcurrentHashMap<String, Object>();
public static Object getValue(String key) {
return container.get(key);
}
public static void setValue(String key, Object value) {
container.put(key, value);
}
} which you could use to persist your native object: var worker = new Worker("./EvalWorker.js");
var nativeObject = new java.io.File("aaa.js");
com.myapp.WorkersContext.setValue("my_key", nativeObject);
var message = {
value: { key: "my_key" }
};
worker.postMessage(message); and then in your background worker retrieve the stored native object: onmessage = function(msg) {
var key = msg.data.value.key;
var nativeObject = com.myapp.WorkersContext.getValue(key);
// ... use the native object here
} |
@darind that's actually a nice idea and easy enough to implement. Would need to find a counterpart for iOS though. |
Does anyone else have issues using existing code NativeScript/Angular code in the worker? |
Hello, I'm having troubles using the geolocation plugin (nativescript-geolocation) inside a worker. I got the following error: Error: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference The error shows when i use the required plugin and execute one of it's functions: const geolocation = require("nativescript-geolocation");
... Is there a way around? or am I doing something wrong? Thx |
Support for Workers
For iOS solution please check - NativeScript/ios-jsc#620
Description
General guidelines for the Workers implementation effort and specification in the context of NativeScript.
We have an existing issue here, but the purpose here is to show the road map that the team intends to follow in developing the Workers functionality. The general scenarios we want to support are listed at the bottom.
Limitations
In NativeScript we don’t need to implement all details of the web workers specification, because some of these details are only related to the browser, and won’t have any meaning in the context of a NativeScript application. The features and syntax that will follow has the purpose of describing the adoption of the web workers specification in NativeScript. In this document we will describe and list what we intend to support.
Guidelines from the specification to follow
context
messaging specifics
messaging transfer ownership
onerror spec
importScripts
Syntax
The following example will be the general syntax to use when working with Workers. Syntax is based on web worker specification.
<app_name>/app/main.js
<app_name>/app/worker.js
Supported APIs:
Worker Object:
Worker Global Object:
Implementation steps:
onerror
handler of the worker object on the main threadThe text was updated successfully, but these errors were encountered: