This factors out the common logic to run over all ZMQ notifiers, call a
function on them, and remove them from the list if the function fails is
extracted to a helper method.
Note that this also fixes a potential memory leak: When a notifier was
removed previously after its callback returned false, it would just be
removed from the list without destructing the object. This is now done
correctly by std::unique_ptr behind the scenes.
This is a backport of core#13686 [2/5]
https://github.com/bitcoin/bitcoin/pull/13686/commits/b93b9d54569145bfcec6cee10968284fe05fe254
Depends on D10282