chaklasiyanikun
4 years agoRoku Guru
Faced "Execution timeout (runtime error &h23)" Error in Function Calculation
I make one sample App for Roku. It is as below.
MainScene.brs
sub init() m.TaskNodeThread = CreateObject("roSGNode", "TaskNodeThread") m.TaskNodeThread.control = "RUN" end sub
MainScene.xml
<?xml version="1.0" encoding="UTF-8"?> <component name="MainScene" extends="Scene" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd"> <script type="text/brightscript" uri="pkg:/components/MainScene.brs" /> </component>
TaskNodeThread.brs
sub init() m.TestContent = testContentFunction(testData) end sub
function testContentFunction(testData as String) as String
'Here I need some calculation and It takes a lot of time.
'It takes around 50 to 60 Sec and I got this error in this function.
'I know Rendered thread timeout limit is 10 Sec that's why I have written this
function in Task Node.
'Even so, it waits only for 10 Sec.
'Can anyone suggest where should I write this type of logic in Roku which is not
affected by UI.
end function
TaskNodeThread.xml
<?xml version="1.0" encoding="UTF-8"?> <component name="TaskNodeThread" extends="Task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd"> <script type="text/brightscript" uri="pkg:/components/TaskNodeThread.brs" /> </component>
Review the documentation on correctly setting up a task
https://developer.roku.com/docs/references/scenegraph/control-nodes/task.md
the way you have set this up 'testContentFunction(testData)' will run when created
MainScene.brs set testdata for task here before "run"
sub init() m.TaskNodeThread = CreateObject("roSGNode", "TaskNodeThread")
m.TaskNodeThread.TestContent=testData
m.TaskNodeThread.observefield("resultContent","onResultContentChanged") 'observe field to see if we are done with task
m.TaskNodeThread.control = "RUN"
end sub
sub onResultContentChanged(event) 'called when task completes
data=event.getdata()
'do stuff with data here
end subTaskNodeThread.xml needs and interface for test content
<?xml version="1.0" encoding="UTF-8"?> <component name="TaskNodeThread" extends="Task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">
<interface>
<field id = "resultcontent" type = "node" /> <field id = "testcontent" type = "node" /> </interface>
<script type="text/brightscript" uri="pkg:/components/TaskNodeThread.brs" /> </component>TaskNodeThread.brs m.top.functionName is what is called when .control="run" is set
sub init()
m.top.functionName = "testContentFunction" end sub
function testContentFunction() as String
testdata=m.top.testcontent
'do stuff here
m.top.resultContent = resultOfStuffDone 'signal task has completed
end function