Skip to content

Commit

Permalink
docs: note re: execution order (see #2261 and #2262)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbj committed Jun 3, 2024
1 parent 2f9cca0 commit 708f38d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions reactive_graph/src/graph/sets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ impl SubscriberSet {

pub fn unsubscribe(&mut self, subscriber: &AnySubscriber) {
if let Some(pos) = self.0.iter().position(|s| s == subscriber) {
// note: do not use `.swap_remove()` here.
// using `.remove()` is slower because it shifts other items
// but it maintains the order of the subscribers, which is important
// to correctness when you're using this to drive something like a UI,
// which can have nested effects, where the inner one assumes the outer
// has already run (for example, an outer effect that checks .is_some(),
// and an inner effect that unwraps)
self.0.remove(pos);
}
}
Expand Down

0 comments on commit 708f38d

Please sign in to comment.