Skip to content

Latest commit

 

History

History
57 lines (51 loc) · 1.98 KB

README.md

File metadata and controls

57 lines (51 loc) · 1.98 KB

Roku Request Executor

Callback based singleton HTTP client for Roku written in BrighterScript

Requirements

  • Handles a queue of multiple simultaneous requests
  • Safe to call from render thread
  • proides a singleton, accessible globally
  • Invokes a callback declared at call site with data from request
    • e.g.
      executorV2()@.enqueuePost(createPostRequest())
      
      function createPostRequest()
        request = createObject("roSGNode", "Request")
        request.headers = { "Content-Type": "application/json" }
        request.body = { randomNumber: StrI(Rnd(55) * 100) }
        request.callBack = {
          componentReference: m.componentReference
          functionName: "printResponse"
        }
        return request
      end function
      
  • Throws an exception if a callback was provided but not function signature matches.

Lifecycle Sequence Diagram

sequenceDiagram
	note over Request: RequestNode w type, body, and callback
	RequestPort->>RequestPort: receiveEvents()
	note over RequestPort: for singleton's lifespan
	Request->>RequestPort: requestExecutorV2()@.enqueuePost(request)
	RequestPort->>RequestQueue: request
	alt there is an available TransferObject	
		RequestQueue->>TransferObjectPool: get TransferObject
		TransferObject->>TransferObject: sendRequest
		TransferObject->>RequestPort: processResponse
		note over RequestPort: request.invokeCallback (if present)
		TransferObject->>TransferObjectPool: return to pool
	else no TransferObjects available
		note over RequestQueue: no-op
	end
Loading

Gif demo

https://i.imgur.com/Rwge8PP.gif gif of load test executing

To-do

  • migrate to roPM
    • maybe--not sure how hard this will be
  • review documentation to make sure it's still correct
  • support other http Methods
    • maybe--we don't have an internal usecase so it's lower priority for me
  • write unit tests
    • I'm unfamiliar with unit testing in bs/brs, but this feels valuable to me