question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to iterate chat.say()

See original GitHub issue

Hi! This is a question more than an issue, but I was wondering how to iterate chat.say() while guaranteeing that it runs in the right order (i.e. synchronously?)

Clearly the following doesn’t work:

for (var i=0;i<arr.length;i++) {
    chat.say(`${arr[i].something}`)
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Charcacommented, Nov 10, 2017

Hey @danielnjoo, chat.say() returns a promise, so maybe you can try doing something like this:

let promise = chat.say('first message')
for (let i = 0; i < 10; i += 1) {
  promise = promise.then(() => chat.say(`message #${i}`))
}

I’m not 100% sure that would work, but it could take you in the right direction.

0reactions
danielnjoocommented, Nov 10, 2017

This works thanks! – clearly I have to brush up on my understanding promises

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the easiest/best/most correct way to iterate through the ...
Benchmarks show String.charAt() is fastest for small strings, and using reflection to read the char array directly is fastest for large strings. –...
Read more >
How to iterate string charcter by character in Python - YouTube
In this video we'll make simple example how to iterate string character by character an print these characters to the string.
Read more >
Iterate Over the Characters of a String in Java - GeeksforGeeks
In this approach, we use the CharacterIterator methods current() to get the current character and next() to move forward by one position.
Read more >
How to Iterate Through a Dictionary in Python
In this step-by-step tutorial, you'll take a deep dive into how to iterate through a dictionary in Python. Dictionaries are a fundamental data...
Read more >
Loops in Ruby - performing repeated operations on a data set
Loops and iterators in Ruby are a great way to perform repeated operations on a data set. Step by step tutorial for the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found