-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Per the readme/spec text, this only works for let or const. I think it should work for using as well. (And I guess await using also.) using specifically allows the RHS to be null or undefined, for cases where a resource needn't be acquired. Integrating with this proposal would let you do
if (using resource = maybeGetResource()) {
// something with resource
} else {
// handle the case of no resource
}(Imagine, for example, a lockIfAvailable API which returns a disposable token to release the lock if the lock is available, or null if the lock is not available.)
Having using work is also valuable for the "extended" form:
if (using resource = getResource(); resource?.needsUpdate()) {
// something with resource
} else {
// ideally the resource is disposed before this block executes
}although the question of when the disposal happens depends on whether the binding is visible in the else, for which, see #3
dcrousso, ljharb, juner, Groupguanfang and legendecas
Metadata
Metadata
Assignees
Labels
No labels