function which wraps a callback and ensures that it is only fired once.