Replies: 12 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 ( |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Above, you almost certainly did not mean Promise.resolve(...).then(...) or its |
Beta Was this translation helpful? Give feedback.
-
@michaelfig and I are thinking about adding E.when(..., ...) as a brief convenience for HandledPromise.resolve(...).then(...) |
Beta Was this translation helpful? Give feedback.
-
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:
|
Beta Was this translation helpful? Give feedback.
-
Further, a bit of experience shows that it covers most of the practical pain we seem to encounter from avoiding |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Yes, our discussion thus far has excluded that form. It's easy enough to break such a |
Beta Was this translation helpful? Give feedback.
-
What would be an example of a use of |
Beta Was this translation helpful? Give feedback.
-
@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(); } |
Beta Was this translation helpful? Give feedback.
-
Surprising // can't use on return expression
return await foo(); With regard to our criteria, we could allow it. However, the |
Beta Was this translation helpful? Give feedback.
-
Eslint rules also ban it, at least the ones we use. |
Beta Was this translation helpful? Give feedback.
-
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
Beta Was this translation helpful? Give feedback.
All reactions