3 ms·
That's interesting. Perhaps it could be called "idle recursion"?
by IsaacSchlueter 17y ago
That's interesting. Perhaps it could be called "idle recursion"?
- jrockway 17y agoIt's not really recursion. It is just a hack around not having a proper event loop. (Note that the function doesn't call itself, it merely adds itself to the event loop's to-do queue. This is a common pattern -- when writing IO watchers, for example, a watcher will often reactivate itself after it is done processing a chunk of input if it expects more input. If it doesn't expect more input, it simply doesn't add itself back.)
- IsaacSchlueter 17y agoI see the distinction. It's not a blocking call, and can't return a value to the original caller, so it might not be correct to call it recursion. (Also, I'm using "recursion" rather loosely here—as we've seen in the recent Guido-vs-TCO debate, not all tail calls are tail recursion. Often when I'm using this pattern, the function isn't calling itself, but rather some other function, such as an event that fires another event when it's done.) So, maybe you're suggesting that the name should not include "recursion"? Still, it would be worthwhile to have a name for this pattern, no? What would you call it?