Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
sgranger
Channel Surfer

callFunc in the same worker thread as Task node?

In order to make a network request, my render thread creates a custom node (let's call it requestNode) that encapsulates the required functionalities for this request, and passes it to a new Task node that will perform the job on a worker thread.

Everything is fine until the Task node does this:

    requestNode.callFunc("parseResponse", responseData)

By doing so, I was expecting the parseResponse heavy work to be performed in the worker thread of the Task node, but after profiling the app, I realized it was actually performed in the render thread instead!

According to the Roku doc: "When a node object is stored in a field, the ownership of the node is changed to the node object that contains the field. When a node object is added as a child of another node object, the ownership is changed to the parent node object."

I tried it both ways (assigning requestNode to a Node field of the Task node, adding it as a child node of the Task node), but requestNode.parseResponse still gets executed in the render thread.

Is there a way for a Task node to execute a function field of another node it owns into its own worker thread?

0 Kudos
1 REPLY 1
sgranger
Channel Surfer

Re: callFunc in the same worker thread as Task node?

Using Node.threadinfo(), I just realized that although the Task node executes in a worker thread, its owning thread still is the render thread. That explains why assigning requestNode to the Task node doesn't change anything in terms of owning thread when it comes to requestNode.callFunc.

At this point, I guess I won't have no other choices but to move all the response parsing functions of my different request components into the Task node itself or in some global source file in order to avoid using callFunc. Or create different Task node components for every different requests.

0 Kudos