Use this tag for questions about features finalized in ECMAScript 2017. Do *not* use this tag if the code in question merely *uses* one of the features, *unless* the feature is cause of the problem.
I have a question about catching user error in async and wait.
Let say I have a route that only fetches for a single user.
routes.js
routes.get('/getuserbyid/:id', (req, res) => {
const id = req.params.id;
accountController.getById(id)
…
I am trying to use async/await and my code works, I just need advice about is it the right way to use async/await, or do I need .then
here. I have a function loadDataForExport - that return promise with generate data. Also, I have actionButtons…
Let's assume we have plain object
const foo = {}
and by using Promise constructor syntax we would add async method to it this way:
foo.myAsyncMethod = function () {
return new Promise((resolve, reject) => {
...
})
}
but we can't do this…
in ES7 we will be having async and await keyword for JS. It looks very promising for regular functions. But how do we handle exception in async events?
for example
async badFunc()
{
throw "bad";
}
var reader = new FileReader();
reader.onload =…
For example, look at this code:
function myPromise() {
return new Promise(resolve => {
setTimeout(() => {
resolve('Stack Overflow');
}, 2000);
});
}
async function sayHello() {
const…
Wanted to use ES8 async/await for my project. Have been using it recently on ReactNative with Expo so didn't expect any problems on ReactJS. Although, the app can't build now...
This is the error I get:
Syntax error:…
This is the code... how would you abort such ajax call?
Or, how to prevent react from giving me an error "setState called on unmounted component"?
(httpGet is just a wrapper for XMLHttpRequest and a promise)
async componentDidMount() {
const…
I want to refactor a promise chain into async/await, but Typescript is complaining about the typing.
TS2322:Type 'IHttpPromiseCallbackArg< IResp >' is not assignable to type 'IResp'...
I thought await would return a regular value, not a promise.…
I'm learning async/await and created a small fiddle @ https://jsfiddle.net/mpycio/rb8taLt7/.
const parse = async (num) => {
let res = await new Promise(resolve =>
setTimeout(() => {resolve(num * 2)}, 0)
)
return…
I have these two different codes that are very slightly different but yield different results:
(async () => {
const results = new Array(concurrentBrowsers).fill({});
const browsers = [];
for (let index = 0; index < concurrentBrowsers; index++)…
I am using ES2017's await keyword, and util.promisify() to use https.get() with await.
Testing connecting to HTTPS with the following code:
const util = require('util'),
https = require('https'),
httpsGet = util.promisify(https.get);
var…
I've been reading up on the new async/await and have been playing around with it in Node 8. I've come across some people putting everything within the initial try block, and others having only the await and all the rest is below the try/catch. Is…
I am trying to reuse the object literals for both async calls. At the end my expect should check the success of the deleteBucket call. Problem is I can't do this, or it says I've got dup variables defined:
it('can delete a bucket', async () => {
…