fix: Wait for fn to end before pushing next message

This commit is contained in:
Sébastien Chopin 2017-09-21 22:42:28 +02:00
parent 27b80739bc
commit 6fd67b68dd

View File

@ -18,10 +18,10 @@ export const messages = [
{ component: 'vText', data: 'End of demo 🎉' }, { component: 'vText', data: 'End of demo 🎉' },
] ]
function streamMessages (fn, i = 0) { async function streamMessages (fn, i = 0) {
if (i >= messages.length) return if (i >= messages.length) return
fn(messages[i]) await fn(messages[i])
setTimeout(() => streamMessages(fn, i + 1), 2000) setTimeout(() => streamMessages(fn, i + 1), 1500)
} }
export default streamMessages export default streamMessages