Created
December 30, 2020 11:03
-
-
Save WebReflection/e91dab813698100a4e0738858d582093 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Sync mixed Async Behavior
This version does not necessarily return a Promise if all template values are not a Promise, but it might be confusing to use ... although, it's a proof of concept.