refactor waitfor to return a promise
a zero-ms timeout is enough