Skip to content

Commit

Permalink
remove monitored items on Unmonitor
Browse files Browse the repository at this point in the history
Fixes #458
  • Loading branch information
magiconair committed Nov 8, 2021
1 parent f52eaa1 commit d11cd84
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func (s *Subscription) Monitor(ts ua.TimestampsToReturn, items ...*ua.MonitoredI
}

// store monitored items
// todo(fs): should we guard this with a lock?
for i, item := range items {
result := res.Results[i]

Expand All @@ -149,10 +150,27 @@ func (s *Subscription) Unmonitor(monitoredItemIDs ...uint32) (*ua.DeleteMonitore
MonitoredItemIDs: monitoredItemIDs,
SubscriptionID: s.SubscriptionID,
}

var res *ua.DeleteMonitoredItemsResponse
err := s.c.Send(req, func(v interface{}) error {
return safeAssign(v, &res)
})

if err == nil {
// remove monitored items
// todo(fs): should we guard this with a lock?
var items []*monitoredItem
for _, id := range monitoredItemIDs {
for _, item := range s.items {
if item.createResult.MonitoredItemID == id {
continue
}
items = append(items, item)
}
}
s.items = items
}

return res, err
}

Expand Down

0 comments on commit d11cd84

Please sign in to comment.