I think it would only work if you had a function that could work as multiple iterations (and you stop iterating when some condition changes), another option may be if it works in a different thread, though I do not how stable it would be if you are allowed to kill the thread
With your function call also start a haxe.timer.delay - if the timer is reached and the promise wasn’t resolved yet, reject the promise
( that doesn’t kill the running function though, but you have essentially a timeout handler. if the function you called exposes cancel methods, call them within the timeout function as well )