Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Actually, the implementation of this sleep function only ever delays until the next tick. In addition, the bug you experience right now is in the code you did not post.
Both of these seem to indicate you haven't done any reasonable amount of debugging on your own. What does a simple thing such as print debugging tell you about all the variables that are relevant?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Your code is wrong. You can save the counter value, see if `saved_counter + sleep_for' is more than the current counter value, and if it is, then stop waiting.
Also, as Combuster said, you can debug the problematic function using usual printing function.