4 ms·
Since the article uses an event system as an example, I'm wondering: how well do closures work in D? (Closures are very convenient when dealing with events).
by amelius 10y ago
Since the article uses an event system as an example, I'm wondering: how well do closures work in D? (Closures are very convenient when dealing with events).
- johncolanduoni 10y agoLooks like they work pretty much the same way they do in most languages: https://dlang.org/spec/function.html#closures https://dlang.org/spec/function.html#closures
- Ace17 10y agoThey work fine. Everything is captured by reference, and is ultimately garbage collected. Unlike C++, you're not required to use a special "local function" syntax.
- amelius 10y agoInteresting. Is this all guaranteed to work also in a multithreaded environment? How efficient is the garbage collector, and are there pauses?
- p0nce 10y ago> Is this all guaranteed to work also in a multithreaded environment? Yes. > How efficient is the garbage collector, and are there pauses? Not very efficient, and there might be pauses if you are not careful. Now if your closure doesn't escape (just a local function + context) it won't use the GC. So you can use delegates in @nogc code.
- mhh__ 10y agoFull closures, function literals, delegates... Basically everything you'd expect.