Skip to content

Allowing using declarations #12

@bakkot

Description

@bakkot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions