Skip to content
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

Genuine question: Why not use already existing syntactic conventions a-la for of ? #186

Closed
lichrot opened this issue Jul 9, 2023 · 2 comments

Comments

@lichrot
Copy link

lichrot commented Jul 9, 2023

Not to sound dramatic, but I'm very concerned by the fact that using breaks already existing intuitions of JavaScript syntax.

Specifically, using messes with variable declarations (let/const/var), while await using gives a false impression of awaiting something on the line it has been used (i.e. it looks like it awaits a possible promise on the right-hand side of the assignment).

Here's an example of syntax that actually fits already established conventions:

const getResource = () => ({
  [Symbol.dispose /* Symbol.asyncDispose */]() { /* do disposal */ }
});

// inline
const resource = getResource();
try {
  /* await */ resource.doSomething();
} finally {
  /* await */ resource[Symbol.dispose /* Symbol.asyncDispose */]();
}

// with keyword
using /* await */ (const resource of getResource()) {
  /* await */ resource.doSomething();
} // `resource` gets disposed here, clear and simple

// with iterators
const getIterResource = () => ({
  [Symbol.dispose /* Symbol.asyncDispose */]() { /* do disposal */ }
  [Symbol.iterator /* Symbol.asyncIterator */]() { /* do iteration */ }
});

for using /* await */ (const resourceChunk of getIterResource()) {
  /* await */ processChunk(resourceChunk);
}

I do not claim to be qualified or provide a comprehensive and robust solution here, but at the very least this example attempts to work within already existing syntactic conventions.

@lichrot lichrot changed the title Genuine question: Why not use already existing syntactic conventions like for of ? Genuine question: Why not use already existing syntactic conventions a-la for of ? Jul 9, 2023
@hax
Copy link
Member

hax commented Jul 10, 2023

@yohgen There are 5 years long discussions about syntax, you could check the old issues, especially #15 and #76 .

@lichrot
Copy link
Author

lichrot commented Jul 10, 2023

@hax Thanks for the pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants