Skip to content

Instantly share code, notes, and snippets.

@noseratio
Created June 2, 2021 07:49
Show Gist options
  • 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