wait-function untested implementation