Hello. Stop a Function

I have a function that loads a bunch of thumbnails. When you click a button it loads a bunch of other thumbnails. If the previous thumbnails load slower, they will load where the current ones should be after the current ones load.

The solution I was thinking of was just killing the old function before starting the next one. I tried using

function = null;
but then it won’t start up again.
I hope that made sense. Thanks.