-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to easily cleanup #11
Comments
@IssueHunt has funded $80.00 to this issue.
|
@sindresorhus Maybe all the functions could accept an option that make it return an array with the original result and a cleanup method. const tempy = require("tempy");
const [tempFile, cleanup] = tempy.file({cleanup: true});
// Use tempFile...
cleanup() We could also add a const tempy = require("tempy");
const [tempFile, cleanup] = tempy.file.cleanable();
// Use tempFile...
cleanup() We could also stick with a callback-like method like in the original proposal: const tempy = require("tempy");
tempy.file.task(tempFile => {
// Use tempFile...
}); I think either of these strategies works best since they are all simple to understand. |
The first suggestion is not desirable as it would complicate the TS types and it would be better to just add a const tempy = require("tempy");
const tempFile = tempy.file();
// Use tempFile...
tempy.cleanup(tempFile); The second suggestion would also not be better than what's above. I think the last suggestion there is the best. |
@sindresorhus Would it also be useful to remove temporary content when the process is killed? |
Yes, but ignoring any failure. |
@sindresorhus exit-hook gets us most of the way, we just need to detect when an error is a reason for exiting. https://stackoverflow.com/a/23197430/8384910 |
@sindresorhus has rewarded $72.00 to @richienb. See it on IssueHunt
|
Offer both cleanup when the process exits, manual cleanup method call, and also a context-based cleanup, for examples:
(The temp directory is cleaned up after the callback scope.)
(The above is just an idea. Please consider a better API and naming.)
(The context callback should also be able to be an
async
function.)Inspiration: Python Context Managers
If you decide to work on this, please put a good effort into the implementation, docs (and TS definition), and tests.
IssueHunt Summary
richienb has been rewarded.
Backers (Total: $80.00)
Submitted pull Requests
Tips
The text was updated successfully, but these errors were encountered: