This function allows me to delay an execution of a function by x amount of time

function delay<TVal>(time: number val: TVal) {  
	return new Promise(resolve => setTimeout(resolve, time, val))  
}