Use low priority events to run generator

This unifies the threaded and non-threaded code: the only difference is
whose event loop the events are processed in. The stop() implementation
is a lot cleaner now as well.