New function zwait that waits for a variable change - due to i/o events