This is a demo of a Trollius event loop for PyPy.js.
PyPy.js is a highly experimental version of PyPy compiled into javascript via Emscripten, with a JIT backend that emits asmjs.
Trollius is a port of the Tulip project (asyncio module, PEP 3156) on Python 2.
The fork of Trollius which contains this pypy.js event loop is developed here.
To use the trollius event loop:
>>> # This import will take a long time... it's fun to watch the console logs. >>> import trollius >>> event_loop = trollius.get_event_loop() >>> >>> def spam(): ... print 'hi' ... >>> event_loop.call_later(3, spam)
For more excitement, try:
>>> from trollius import From, coroutine >>> @coroutine ... def count(): ... for i in xrange(10): ... print i ... yield From(trollius.sleep(1)) ... >>> >>> a = trollius.async(count())