Requesting an Iterator, stop processing it and closing the database results in an error:
This database connection is busy executing a query.
Which is the correct way to abort an iteration?
Use iterator.return().
var stmt = db.prepare('SELECT * FROM my_table');
var iterator = stmt.iterate();
var { value } = iterator.next();
iterator.return(); // this will close the iterator
db.close();
If you use a for of loop, it will automatically call iterator.return() when you exit the loop (via a break, return, throw, etc.). These features are only supported in Node.js 6+
Thank you. I'm using Kotlin, so no JavaScript syntax at all. When an exception is thrown return isn't called in Kotlin.
Most helpful comment
Use
iterator.return().If you use a
for ofloop, it will automatically calliterator.return()when you exit the loop (via a break, return, throw, etc.). These features are only supported in Node.js 6+