-
Notifications
You must be signed in to change notification settings - Fork 16
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Add async and a restricted form of await #45
Comments
It is not primarily the hazard keeping it out of Jessie, though that is an issue. The hazard is that, when both writing and reading a program, especially when reading other people's programs, an explicit One of the goals of Jessie is that it be easily implementable by a straightforward eval/apply style interpreter on top of a great variety of other languages. Both
The first two are not simple. The last is not universally available across desired host languages. Interesting discovery since then, due to @dtribble:
The semantics of an async function without Thus, we will include By the same reasoning, it would be safe to include generators ( And finally, it would be safe to include async generators ( |
FWIW, my use case is using JavaScript tools to develop contracts to run on RChain, with hopes of actually running Jessie / Zoe / ERTP contracts on RChain. For example, 2.check_balance.rho begins with the following, where new
rl(`rho:registry:lookup`), RevVaultCh,
vaultCh, balanceCh,
stdout(`rho:io:stdout`)
in {
rl!(`rho:rchain:revVault`, *RevVaultCh) |
for (@(_, RevVault) <- RevVaultCh) {
... I have convinced the machine to take check_balance.js starting this way: import { tuple } from '@rchain-community/js2rho';
import rl from 'rho:registry:lookup';
import E from '@agoric/eventual-send';
export default
async function main() {
const { _0: _, _1: RevVault } = await E(rl)('rho:rchain:revVault');
... and deal with the boring syntax bits for me to produce check_balance.rho: new rl(`rho:registry:lookup`),
console(`rho:io:stdout`)
in {
new AwaitExpression_9c36_0
in {
rl!("rho:rchain:revVault", *AwaitExpression_9c36_0)
|
for(@{ (*_, *RevVault) } <- AwaitExpression_9c36_0) {
... The |
Above, you almost certainly did not mean Promise.resolve(...).then(...) or its |
@michaelfig and I are thinking about adding E.when(..., ...) as a brief convenience for HandledPromise.resolve(...).then(...) |
We have now decided to add functionBody ::= (topLevelDeclaration | topLevelStatement)*;
topLevelDeclaration ::=
("const" | "let") destructingPattern "=" "await" expression ";"
| declaration; // existing Jessie declaration without "await"
topLevelStatement ::=
"await" expression ";"
| statement; // existing Jessie statement without "await" Your example above async function main() {
const { _0: _, _1: RevVault } = await E(rl)('rho:rchain:revVault');
...
} is within this grammar, because it occurs only at the top level of a function, and it precedes the entire initialization expression. This should adequately satisfy both criteria:
|
Further, a bit of experience shows that it covers most of the practical pain we seem to encounter from avoiding |
The permitted form would exclude catching an exception, right?: async function main() {
try {
await E(x).foo();
} catch (err) {
react_to(err);
}
} I think that's probably fine, and I imagine the interpreter/transform would be more complicated if it needed to allow this case.. just wanted to check. |
Yes, our discussion thus far has excluded that form. It's easy enough to break such a |
What would be an example of a use of |
@warner 's example above is one. Some others: // Can't nest `await` within an expression
foo(await bar());
// can't use within a control construct
if (await foo()) { ... }
if (...) { await foo(); } |
Surprising // can't use on return expression
return await foo(); With regard to our criteria, we could allow it. However, the |
Eslint rules also ban it, at least the ones we use. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
parse-time detection of async / await is too handy for a js2rho project I'm working on, but I recall some discussion of the hazard.
Would you please either
The text was updated successfully, but these errors were encountered: