Can't you use waitForCondition() here?