I'm trying to create a asynchronous action on Svelte (use:action
directive), it works fine when i try the following "non-async" function
export default function typewriter(node, options) {
for (const letter of elementsText[elIndex]) {
if (!reverse && el.textContent === elementsText[elIndex].join('')) return
if (reverse && el.textContent === '') return
if (Array.isArray(interval)) {
const randomInterval = Math.floor(Math.random() * interval.length)
// this function needs an `await`
await sleep(interval[randomInterval])
} else if (typeof interval == 'number') {
// this function requires an `await`
sleep(interval)
}
!reverse ? (el.textContent += letter) : (el.textContent = el.textContent.slice(0, -1))
}
}
But when i try to transform the code above into a asynchronous function, i get the following error (probably, thrown by babeljs)
Uncaught (in promise) ReferenceError: regeneratorRuntime is not defined