Cooperative multithreading in Javascript using generators