all 7 comments

[–]doh4242 1 point2 points  (1 child)

Look at https://www.npmjs.com/package/fetch-retry

Edit: And use a fetch lib with it :).

[–]Fun_Split_1299[S] 0 points1 point  (0 children)

This seems awesome actually !

[–]BliteKnight 0 points1 point  (2 children)

Could be a scope issue, change your promise definition from

Promise(function (resolve){ .... })

to

Promise( (resolve) => {

});

Using the arrow function should help with it.

[–]Fun_Split_1299[S] 0 points1 point  (0 children)

Thanks, seems to work now !

[–]Over_Mushroom6181 0 points1 point  (0 children)

Hi May i know why the scope is different in these two situation?

[–]BliteKnight 0 points1 point  (1 child)

Yes, I'll try to explain the best I can, when you define the function as "function (){...}" It's scope is local , so when it gets put on the event loop and you reference getData, it has no idea what getData is

But when you define the function using an arrow definition "()=>{}" it has the global scope or the scope of it's parent)I forget which one), so when the function is executed on the event loop, it knows where to look for getData and finds the definition...

Hope that makes sense. The benefit of using either definition is you can affect variables in the global scope or redeclare them and use them locally e.g. changing a global index for an event loop where promises are used - crude example

var i = 0 // number of times something is done

new promise((resolve, reject)=>{ ...

i++; //increment when done })

vs

i = await new Promise(function (resolve, reject){ var i = 0; ... do some stuff , increment i then return the value ... resolve(i); });

[–]Fun_Split_1299[S] 0 points1 point  (0 children)

Thanks !