ensure iterator end & next don't conflict

Race condition possible when you have a next() executing but end() is
also called. In the main JS thread we can create a barrier to protect
against this condition.