how do you detect loops without a timeout or something?