Comments (3)
While the general ideas are related, it's not clear to me that (in practice) this would actually help much. In particular, goog.Disposable
objects tend to live for a medium-to-long amount of time, typically bounded by a "parent object"'s lifetime, which is a pretty different paradigm than a function scope. Given that, I don't see how linking these things would be useful.
In general, Disposable
is a pretty archaic/crufty class that we're mostly trying to move away from, so I'm inclined to avoid making this sort of change to it. Can you provide some more concrete use cases in the context of an actual application that would benefit from this?
from closure-library.
Sure, and yeah we have a lot of Disposables that live a long time.
The most obvious case is our unit tests:
it('should do stuff', () => {
using injector = createInjector();
const item = injector.get(UnitUnderTest);
// test
});
vs.
it('should do stuff', () => {
const injector = createInjector();
const item = injector.get(UnitUnderTest);
// test
injector.dispose();
});
It would also be convenient in occasional functions that create short lived versions of classes that are disposable, just to do some processing, get a result, and return the result.
function f() {
using someDisposable = new SomeDisposable();
return someDisposable.someComputation();
}
vs.
function f() {
const someDisposable = new SomeDisposable();
const result = someDisposable.someComputation();
someDisposable.dispose();
return result;
}
Neither of these cases actually need the try {} finally {}
behavior, as exceptions are rare and leaks aren't catastrophic, but having it certainly wouldn't harm anything.
from closure-library.
Thanks for those use cases. Presumably Closure Compiler will want to transpile using
syntax, so it will likely be polyfilling Symbol.dispose
, which we'd want to somehow piggyback on. Given the coordination requirements, we need to do a bit of designing internally, but we'll be looking into it this next quarter or so.
from closure-library.
Related Issues (20)
- C language HOT 1
- Demos page not found. HOT 3
- [Breaking Change] In-browser transpilation turning down July 25 HOT 1
- unsafeClone clobbers Dates
- Alternative to goog.ds? HOT 4
- SafeUrl.fromDataUrl returns invalid for image/svg+xml mime type HOT 2
- `goog.color.blend` appears to perform Simple Alpha Compositing than actual Blending per W3C spec HOT 1
- Some UI widgest can't be used under Bazel due to files under //closure/goog/css being un-referenceable. HOT 4
- Mark goog.ui as "not for new application" or some sutch. HOT 1
- Unknown code on my site - Copyright The Closure Library Authors. SPDX-License-Identifier: Apache-2.0 HOT 1
- `npm install` failed to generate `deps.js` HOT 10
- bazel build at/near head fails in multiple ways. HOT 3
- goog.editor.Command.EDIT_HTML doesn't work in Closure Editor HOT 2
- TypeError: Cannot read properties of undefined HOT 2
- `goog.dom.appendChild` documentation lists incorrect type HOT 1
- URIs with empty fragments are not preserved HOT 1
- Firefox specific execCommands no longer needed HOT 3
- Closure Library is in Maintenance Mode HOT 19
- import malware
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from closure-library.