1

Topic: [js] the Synchronous request

,  please how in  synchronously to take a file from the server? Or how to wait executions  and to take therefrom data retrieveds? Tried so: async load_url (url) {console.log (' loading ' + url); return await axios.get (url).then (({data}) => {//console.log (data) return data;}).catch (function (error) {console.log (error); return {};}); console.log (' loading ' + url + ' done ');} It is returned promise... Where leaves data? How to me it to take therefrom?

2

Re: [js] the Synchronous request

Hello, Sheridan, you wrote: S> Kamrady,  please how in  synchronously to take a file from the server? In any way. There all asynchronous. That life honey did not seem. S> It is returned promise... S> Where leaves data? How to me it to take therefrom? Promise is such disguised . When loading will be completed, yours  call, and here then there will be data. For now - only the promise of the data

3

Re: [js] the Synchronous request

Hello, Sheridan, you wrote: S> Kamrady,  please how in  synchronously to take a file from the server? Most simple - await fetch (URL) But so the mistake tells... It is necessary one more unobvious step async test () {await fetch (URL)} test (); Synchronism is normally necessary in games where not  execution, and in a game cycle, in JS it is with screen update rate. If at you not game, and type a site that it is possible and to manage without synchronism... Yes in games too it is possible... But it is sometimes convenient...

4

Re: [js] the Synchronous request

Hello, Sheridan, you wrote: S> It is returned promise... async function always returns it. S> where leaves data? How to me it to take therefrom? Make await to result.

5

Re: [js] the Synchronous request

Hello, Ops, you wrote: S>> It is returned promise... Ops> async function always returns it. S>> where leaves data? How to me it to take therefrom? Ops> make await to result. , it should be made as that on another, than in a slice of the code which was in the start message? However, I  turned inside out the code, all works, thanks

6

Re: [js] the Synchronous request

Hello, Sheridan, you wrote: S> Kamrady,  please how in  synchronously to take a file from the server? Time is already async await, what for then and catch when it is possible to use try-catch? async load_url (url) {console.log (' loading ' + url); try {const {data} = await axios.get (url); console.log (' loading ' + url + ' done '); return data;} catch (error) {console.log (error); return {};}}

7

Re: [js] the Synchronous request

Hello, Sheridan, you wrote: S> Druzhe, it is necessary to make it as that on another, than in a slice of the code which was in the start message? Yes, await it is necessary to your function load_url when you cause it.