Await within a synchronous function

Asked

Viewed 21 times

0

I made a program that trains a neural network to play old game with the user. I need to rescue the value returned by the method this.academy.step, which contains the position of the next computer move, but instead of the desired value, my code is returning a promise.

var result = (async() => 
        await this.academy.step([{teacherName: this.teacher, agentsInput: inputs}]))();
  • pole the this.academy.step? also

  • 1

    You cannot wait for the return of a promise in a synchronous function. I see two options: convert the function to async or use the callback within the then to access the solved promise value in the synchronous function. To learn more, see here and here.

  • Virgilio Novic this method I took from the Reimprovejs library

  • There is no await within synchronous functions, read only the first two paragraphs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await

No answers

Browser other questions tagged

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