Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You are right. I _think_ what they meant to say was that the deferred can only fire once. You cannot call .callback() twice. Or adding deferreds to it after it fired won't get those functions called.

However, even with respect to your example, it is not idiomatic. Yes you can do anything on anything in Python. And in testing you often monkey-patch and mock things. Which doesn't mean you'd do often in production code. The idea of deferreds is to help with highly concurrent IO applications. It will be a file descriptor (socket) or a timer that will fire your callback more than often.



They get used quite often in production code quite often too: any time you have a synchronous implementation to an asynchronous interface. E.g. your DNS name resoltion thing may have to go query a Postgres database far away (that'd be asynchronous), but maybe it has to grab an entry from a (Python) list (that'd be synchronous).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: