Forum Discussion
First off, your task is not set up correctly
sub init() m.top.functionName = "codeToRun" 'what will be called on task.control ="RUN" end sub function codeToRun() 'do stuff here end function
as you have it the task will do stuff only when created of task.control ="init"
since this is in a task and should be running on a no blocking thread try
msg = Wait(1, m.port)
otherwise you are waiting 3000 milliseconds each loop
- chaklasiyanikun5 years agoRoku Guru
I already tried which you suggest. My Task node like below :
sub init()
?"Start - init()" m.top.functionName = "MakePostRequest" 'Roku execution skips this line in my case.
?"End - init()" end subfunction MakePostRequest()
?"Start - MakePostRequest" 'The call doesn't come here
readdata = CreateObject("roUrlTransfer") data = "http://Domain:Port" readdata.setUrl(data) readdata.SetMinimumTransferRate(1, 75) ? "data is " data m.port = CreateObject("roMessagePort") readdata.setport(m.port) readdata.gettostring() readdata.SetRequest("POST") request = readdata.AsyncPostFromString(data) ?"request : " request while (true) msg = Wait(0, m.port) statusCode = msg.GetResponseCode() if (Type(msg) = "roUrlEvent") statusCode = msg.GetResponseCode() headers = msg.GetResponseHeaders() if msg.getresponsecode() = 200 then Response = msg.getstring() headers = msg.getresponseheadersarray() ?"Response : " Response exit while else m.top.isError = "true" m.readdata.asynccancel() exit while end if
else ? "wait for data" end if end while
?"End - MakePostRequest"
end functionI make a separate project for this but here also result is the same.
I have to do is stand there until there is a response. Because I created multiple Task nodes and every task node Depends on Each Other. Currently, your ways are happening like => Consider I used 3 Task node. so First It's 2nd Task node Response comes. After 3rd Task node Response comes then it's Run 1st Task node Response comes. But I need to run 1st, 2nd, 3rd wise.
- necrotek5 years agoRoku Guru
Are you sure that your "task" xml extends task? not sure why it would skip that line. "functionName" is the field that is called as a function when you "run" a task.
https://developer.roku.com/docs/references/scenegraph/control-nodes/task.md
since this is a task and not blocking, omit the while loop and don't do async
urlhost = CreateObject("roUrlTransfer") urlhost.SetCertificatesFile("common:/certs/ca-bundle.crt") urlhost.AddHeader("X-Roku-Reserved-Dev-Id", "") urlhost.InitClientCertificates() urlhost.SetUrl(m.top.url) rsp = urlhost.GetToString() ResponseJSON = ParseJSON(rsp)