3 ms·
You can compare the two styles in Tornado: plain Tornado uses callbacks, or you can code with generators using e.g. http://code.naeseth.com/swirl/ http://code.n
by ntoshev 16y ago
You can compare the two styles in Tornado: plain Tornado uses callbacks, or you can code with generators using e.g. http://code.naeseth.com/swirl/ http://code.naeseth.com/swirl/
In practice everyone uses plain Tornado with callbacks. The problem with generators as coroutines to me is that you can't compose them nicely: you can't call a subroutine that yields, you must yield only from your top level. This and the fact that it's another layer of leaky abstraction.
- krosaen 16y agogood point, I think I ran into that when I was playing with coroutines to build a simple finite state machine to parse something; as soon as it got the least bit complex, I was like, "you mean I can't extract a generator!?" I was originally inspired by this post: http://eli.thegreenplace.net/2009/08/29/co-routines-as-an-alternative-to-state-machines/ http://eli.thegreenplace.net/2009/08/29/co-routines-as-an-al... and was thrilled with how clever it all seemed, but in practice, it seems to be stretching the capabilities of the yield statement too far
- ntoshev 16y agoActually, he does provide a solution to this, in the section "Tasklets and futures". It's not simple though.