5 ms·
I don't know if the pattern has a name, but equivalent of this in GTK+ (and QT, IIRC) desktop world would be called an idle callback (function scheduled to be r
by senko 18y ago
I don't know if the pattern has a name, but equivalent of this in GTK+ (and QT, IIRC) desktop world would be called an idle callback (function scheduled to be run at the next iteration of the event loop).
More info here: http://developer.gnome.org/doc/GGAD/sec-mainloop.html#Z63 http://developer.gnome.org/doc/GGAD/sec-mainloop.html#Z63
- IsaacSchlueter 18y agoThat's interesting. Perhaps it could be called "idle recursion"?
- jrockway 18y 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 18y 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?