Forum Discussion
sjb64
3 years agoRoku Guru
To use HTTP calls, you do have to use a task, this is a requirement of the platform.
But tasks are meant to receive information (via a field) and act on it, or to set fields that other threads can read (like preloading a catalog). It doesn't do well doing both as a unit. It's not like a function where you call it and wait for a response. When you say call it in welcome_screen and act on it in welcome_screen, this makes me think a 2 way call and return value that is your intent.
So you have a few options:
- Know what you want to call (the api details) in advance, do it when the task initially runs, then get the data when you later need it. This is useful for preloading a catalog from a known source.
- Call the task as needed with the api details using a task observed field, and observe a second task field in the render thread. When the task gets the request, performs the HTTP call, gets the response, and changes the second field your render thread will trigger on the change and you have your task result and can update you screen accordingly.
- Clear a tmp file variable, call the task thread, have it create the temp file with the data once completed. Meanwhile the render thread is watching for that that file using a timer. This is the messiest option, but the one that has worked for me in the past to make a task call behave like a function.
- The community (rokudevelopers.slack.com) has a couple of promise type mechanisms made for this situation, although I am not personally familiar with them.
- avishka3 years agoReel Rookie
I was able to get API data when did the second option. sound like I should need to understand so many things related to web services communication of brightscript. 😶