Calls a function repeatedly if a condition returns false and until the condition returns true and then resolves the promise