Commit c39d701
fix: guard against double-unsubscribe removing wrong subscriber in cache.ts (#4252)
fix: guard against double-unsubscribe removing wrong subscriber
When the unsubscribe function returned by `subscribe` was called more
than once, `subs.indexOf(callback)` returned -1, causing
`subs.splice(-1, 1)` to silently remove the last subscriber in the
array instead of doing nothing.
Fix by checking `index >= 0` before mutating the array, using the same
O(1) swap-and-pop pattern already used in `subscribe-key.ts`.
Signed-off-by: tomohiro86 <supersonic.dps@gmail.com>
Co-authored-by: Tomohiro Yamada <tomohiro.yamada@TomohironoMacBook-Air.local>1 parent 46f3954 commit c39d701
1 file changed
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
60 | 67 | | |
61 | 68 | | |
62 | 69 | | |
| |||
0 commit comments