Hierarchy of requests with Await

Asked

Viewed 36 times

0

Next... I need to make a hierarchy of requests that depend on each other.

I did the whole structure, but when I run the code they are solved asynchronously, without waiting for the resolution of a request to follow the code just below.

Follow the structure as it is:

This is the requisition where it’s made requisicao

This is the method in service: servico

After Syncdevices the Request Hierarchy starts: syncdevices

And after fetchHeaders has several others as well as in Syncdevices, one depending on the other and being solved one after the other. But I need to solve the Tryrecconectaccount function because having her answer I can remove the loading on the screen.

If anyone has any idea what I can do... Thank you

  • I think the correct word would be "asynchronous". D

  • 1

    Do not put code as image. Instead put as text formatting appropriately through the editor in question. This allows someone to play the code you have more easily. Ideally, until you create a Minimum, Complete and Verifiable Example of the problem.

1 answer

3

That’s not a verifiable example, so I don’t know if that’ll be enough, but I can see some problems in your code.

The function tryReconnectAccount, despite being asynchronous, does not expect the return of this.syncDevicesFeatures, it just calls the function and immediately returns undefined (every function without explicit return returns Undefined) before that syncDevicesFeatures finish running.

If syncDevicesFeatures return a file (or is async), you could use

 async tryReconnectAccount(data, headers, props, account) {
     return await this.syncDevicesFeatures(data, headers, props, account);
 }

I’m actually not seeing any reason for tryReconnectAccount to exist, since it only invokes syncDevicesFeatures with the same parameters.

  • Thank you for the moral. The tryReconnectAccount was made for testing and forgot to delete :D. But the syncDevicesFeatures being returned this way with the await it tbm expects the other functions being called inside it?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.