Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Description
TypeScript now supports Disposables: objects that have some "dispose" behavior when they go out of scope.
It's important to use using and not const/let when using those objects, otherwise the automatic cleanup does not happen and you would leak resources.
Fail Cases
In this case we are opening a file through an API that expects to be disposed, but we are not using it as such. The readConfig function will thus leak resources associated to the opened file.
declare function openFile(url: string): Disposable & MyFileAPI;
function readConfig() {
const configFile = openFile("./configFile");
return configFile.contentsAsJson();
}
Pass Cases
In this case we are properly disposing the file resource.
declare function openFile(url: string): Disposable & MyFileAPI;
function readConfig() {
using configFile = openFile("./configFile");
return configFile.contentsAsJson();
}
Additional Info
This is the equivalent to require-await, but for Disposables rather than Thenables.
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Description
TypeScript now supports Disposables: objects that have some "dispose" behavior when they go out of scope.
It's important to use
usingand notconst/letwhen using those objects, otherwise the automatic cleanup does not happen and you would leak resources.Fail Cases
In this case we are opening a file through an API that expects to be disposed, but we are not using it as such. The
readConfigfunction will thus leak resources associated to the opened file.Pass Cases
In this case we are properly disposing the file resource.
Additional Info
This is the equivalent to
require-await, but for Disposables rather than Thenables.