4 ms·
For those wanting a real world example where this can be useful: I am writing a static site generator. When run in "watch" mode, it deletes everything and star
by epage 6y ago
For those wanting a real world example where this can be useful:
I am writing a static site generator. When run in "watch" mode, it deletes everything and starts over (I'd like to reduce these with partial updates but can't always do it). Moving that cleanup to a thread would make "watch" more responsive.
- firethief 6y agoWhy can't it cleanup right after the work?
- pmontra 6y agoOr no cleanup at all. A CLI command that runs for a very short time can allocate memory to perform its job, print the result and exit. Then the OS releases all the memory of the process. No idea if Rust can work like this.
- estebank 6y agostd::mem::forget, which doesn't run destructors: https://doc.rust-lang.org/std/mem/fn.forget.html https://doc.rust-lang.org/std/mem/fn.forget.html
- ReactiveJelly 6y ago"Watch mode" for static site gens would mean you leave the process running and let it rebuild the site whenever a file changes, probably 10s to 100s of times in a typical run
- elcomet 6y agoThat's not really the same issue that is mentionned in the article though, is it ? The issue from the article would be solved by just passing a reference to the variable. In your case, cleanup is an action that needs to be done before writing new files. So you have to wait for cleanup anyway, don't you ?
- ashtonkem 6y agoThat's not true. Typically any server with a watch functionality will have a mutable reference to the data that's being watched. When you change that data out you're both changing the mutable reference, and also deallocating any memory that was previously used. One could separate these two steps, moving the watched data to another variable that's dropped in another thread, if you wanted.