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.

Make Collections iterable

See original GitHub issue

Currently cannot use code similar to this to loop a Collection:

let dataRows = await MyTable.where({someValue: 7}).fetchAll();
for (let row of dataRows) {
    // do something on row
}

Get: TypeError: dataRows is not iterable

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
leebickmtucommented, Apr 18, 2018

That would be valid in that it would make the awaited Promises within each forEach iteration synchronous. But each iteration would be asynchronous to the main function without a way to await each iteration.

Try this for example. Each iteration will wait for the timeout to resolve back with the row to rowValue then print it. So synchronous within an iteration. But they will print in the order 1,2,3,4 (not the iteration order) because each iteration is asynchronous relative to the others. And you will see ‘after loop’ print before any of them cause the main code can’t await each iteration either.

let dataRows = [2,1,4,3];
dataRows.forEach( async (row) => {
    let rowValue = await new Promise(function(resolve, reject) {
        setTimeout(resolve, row*1000, row);
    });
    console.log(rowValue);
})
console.log('after loop');
0reactions
ricardogracacommented, Apr 20, 2018

Duplicate of #1525.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Collection to Iterable - java - Stack Overflow
Iterable is a super interface to Collection , so any class (such as Set or List ) that implements Collection also implements Iterable...
Read more >
Collections - Iterable Support Center
Navigate to Content > Catalogs. · Click Collections (on the left-hand side of the screen). · Use the Filter box to filter the...
Read more >
Java Iterable - Jenkov.com
The Java Iterable interface represents a collection of objects which is iterable - meaning which can be iterated.
Read more >
Converting Iterable to Collection in Java | Baeldung
Learn how to convert an Iterable to a Collection with a core Java solution or other libraries.
Read more >
Iterable collections - Dart programming language
An Iterable is a collection of elements that can be accessed sequentially. In Dart, an Iterable is an abstract class, meaning that you...
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