Skip to content
Discussion options

You must be logged in to vote

Edit

Pardon, j'avais mal compris. await n'est normalement pas disponible au premier niveau, il faut l'utiliser dans une fonction asynchrone:

async function thisIsAnAsyncFunction() {
  // Here, you can wait for promises with 'await'
}

Tu n'as pas besoin de convertir ton projet vers les modules, même si c'est plus pratique. Si ça ne marche pas dans les fonctions, c'est peut-être parce que tu n'as pas utilisé async. Si tu veux revenir à CommonJS (avec require et sans les await de premier niveau), tu peux le faire. En général, on fait ça pour utiliser await en CommonJS au premier niveau:

(async () => {
  // Here is the code; it's actually defining an async function and then executing it.
  //…

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@a2br
Comment options

a2br Jun 19, 2021
Maintainer

@MixtarMaster
Comment options

@JsonLinesCode
Comment options

@a2br
Comment options

a2br Jun 20, 2021
Maintainer

@MixtarMaster
Comment options

Answer selected by MixtarMaster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants