Skip to content

Instantly share code, notes, and snippets.

@sajadmsNew
Forked from WebReflection/async-tag.js
Created September 24, 2021 22:02
Show Gist options
  • Select an option

  • Save sajadmsNew/9247aafdf62895477a38f394a00d0acc to your computer and use it in GitHub Desktop.

Select an option

Save sajadmsNew/9247aafdf62895477a38f394a00d0acc to your computer and use it in GitHub Desktop.
const {isArray} = Array;
const sync = async values => {
for (let {length} = values, i = 0; i < length; i++) {
const value = await values[i];
values[i] = isArray(value) ? await sync(value) : value;
}
return values;
};
const asyncTag = tag => async (template, ...values) =>
tag(template, ...(await sync(values)));
// example
const asyncRaw = asyncTag(String.raw);
asyncRaw`a${Promise.resolve('b')}c`
.then(console.log); // "abc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment