add functionality to execute code on the destruction of tasks