Collider notified after removal

I have 10 images moving towards rectangles. I want to stop each one when it hits a rectangles, and remove the collider when all of them have stopped:

let hits = new Set();
let hands = scene.hands;
let w = scene.physics.world;
let col = scene.physics.add.overlap(og, rg, function(go, rect){
    go.body.stop();
    hits.add(go);
    console.log('collided : '+hits.size);
    if (hits.size == data.length) {
        console.log("removing collider");
        w.removeCollider(col);
    }
});         

This works but, surprisingly, I see multiple “collided: 10” and “removing collider” message pairs. Is this safe? Is there a better way to do this?

I would add a process callback:

const MAX = 10;
const hits = new Set();

let collider = this.physics.add.overlap(
  A,
  B,
  function(a, b) {
    hits.add(a);
  },
  function(a, b) {
    if (hits.size >= MAX) {
      this.world.removeCollider(collider);

      return false;
    }

    return hits.size < MAX;
  },
  this
);