Depends.
I'd say the set piece is over once any of the following things happen: a) the ball goes in the net, b) the ball goes out of play, c) the ball is cleared by the defence, d) the defending team takes possession of the ball or e) the ball is retained by the attacking team but they have...