From the miner perspective: You have a worker, fetching data from a full-node with
getblocktemplate to create a candidate block and push it to the miners, to effective mine it. As soon as your miner is done mining a candidate, it asks for more data. However if the block being mined now, was submitted by another miner, all miners should stop to work in the current block and pull data from worker.
How can the worker identify as soon as possible that a new block was mined? Monitor if the
height on the results from
getblocktemplate changed? Monitor if previous hash changed? Monitor if at least X confirmations happened?