Skip to content

Commit

Permalink
Improved the cleaning observer process on RTA_OnDeviceComponent.brs
Browse files Browse the repository at this point in the history
  • Loading branch information
efernandes-bcov committed Nov 25, 2024
1 parent 6444846 commit 5445bd5
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion device/components/RTA_OnDeviceComponent.brs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,13 @@ function processCancelOnFieldChangeRepeat(request as Object) as Dynamic
args = request.args
cancelRequestId = args.cancelRequestId
if cancelRequestId <> invalid and m.activeObserveFieldRequests[cancelRequestId] <> invalid then
m.activeObserveFieldRequests.delete(cancelRequestId)
deletedRequest = m.activeObserveFieldRequests[cancelRequestId]
if m.activeObserveFieldRequests.delete(cancelRequestId) then 'We should remove the observer first
if deletedRequest.node <> invalid and deletedRequest.args <> invalid and deletedRequest.args.field <> invalid then
cleanObservers(deletedRequest.node, deletedRequest.args.field) 'Remove the observer if there is no more requests using it
deletedRequest = invalid
end if
end if
RTA_logDebug("Deleted Active Request ID " + cancelRequestId)
sendResponseToTask(request, RTA_buildSuccessResponseObject("Successfully removed the continuous observer!"))
return invalid
Expand All @@ -467,6 +473,23 @@ function processCancelOnFieldChangeRepeat(request as Object) as Dynamic
return invalid
end function

sub cleanObservers(node, field, data = invalid)
remainingObservers = 0
request = invalid
for each requestId in m.activeObserveFieldRequests
request = m.activeObserveFieldRequests[requestId]
args = request.args
if node.isSameNode(request.node) AND args.field = field then
remainingObservers++
end if
end for
if remainingObservers = 0 then
' If we got to here then we sent back all responses for this field so we can remove our observer now
RTA_logDebug("cleanObservers: Unobserved '" + field + "' on " + node.subtype() + "(" + node.id + ")")
node.unobserveFieldScoped(field)
end if
end sub

sub onProcessObserveFieldRequestRetryFired(event as Object)
requestId = event.getNode()
request = m.activeObserveFieldRequests[requestId]
Expand Down

0 comments on commit 5445bd5

Please sign in to comment.