await/async syntax
Posted: 2017-07-11, 21:33
There's a nifty idea in javascript lately that is a syntax for making Promises easy to use. Palemoon doesn't support it, but I'd certainly appreciate if it did. Basically something like
async function someops() {
let a = await getapromise();
let b = await getanotherpromise();
return a + b
}would be transformed into something like:
function someops() {
var trace1, trace2, trace3;
trace1 = getastacktrace();
return getapromise().then(function (a) {
trace2 = getastacktrace();
return getanotherpromise().then(function(b) {
trace3 = getastacktrace();
return a + b;
}).catch(function(e) {
global_handle_error(e,combine_traces(trace3,trace2,trace1));
});
}).catch(function(e) {
global_handle_error(e,combine_traces(trace2,trace1));
});
}
...except written by someone who actually understands how to javascript.
async/await syntax allows for asynchronous error handling using try/catch blocks, eliminates any callback hell, preserves stack traces, is easier to debug, and um... allows for certain optimizations that passing a function closure to then() couldn't take advantage of if it wasn't built into the language.
Has there been any luck just... substituting a newer javascript engine in, that supports await syntax?
async function someops() {
let a = await getapromise();
let b = await getanotherpromise();
return a + b
}would be transformed into something like:
function someops() {
var trace1, trace2, trace3;
trace1 = getastacktrace();
return getapromise().then(function (a) {
trace2 = getastacktrace();
return getanotherpromise().then(function(b) {
trace3 = getastacktrace();
return a + b;
}).catch(function(e) {
global_handle_error(e,combine_traces(trace3,trace2,trace1));
});
}).catch(function(e) {
global_handle_error(e,combine_traces(trace2,trace1));
});
}
...except written by someone who actually understands how to javascript.
async/await syntax allows for asynchronous error handling using try/catch blocks, eliminates any callback hell, preserves stack traces, is easier to debug, and um... allows for certain optimizations that passing a function closure to then() couldn't take advantage of if it wasn't built into the language.
Has there been any luck just... substituting a newer javascript engine in, that supports await syntax?