Skip to content

Instantly share code, notes, and snippets.

@noseratio
Created June 2, 2021 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noseratio/621b208ea72a8056654ce08b84fccac8 to your computer and use it in GitHub Desktop.
Save noseratio/621b208ea72a8056654ce08b84fccac8 to your computer and use it in GitHub Desktop.
Awaiting inside JavaScript template strings
// https://dev.to/noseratio/await-inside-javascript-template-strings-3kbj
//
// save this as .mjs or as "node --input-type=module < file.js"
const delay = (ms, result) => new Promise(r => setTimeout(r, ms, result));
const interpolated = `Hello, ${await delay(1000, "World!")} Is this sync or async?`;
console.log(interpolated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment