javascript - Return only certain yield in generator(iterator) function -


i this.

function* iteraterecord() {      const db = yield mongoclient.connect('');      const collection = db.collection('');      const query = {}       const cursor = collection.find(query);      while (yield cursor.hasnext()) {          const bsonobject = yield cursor.next();     } }  for(record of iteraterecord()) {     //do stuff } 

now can see not work db yield first iteration of for. return yield @ cursor.next.

is possible? have tried few things multiple yield not part of iteration.

thanks

you're mixing 2 different things here: (1) js generators , (2) usage of js generators emulate async/await.

there number of libraries (2) co or bluebird, of them expect you're going yield promises.

it not work for loop sure because doesn't wait promises resolve , doesn't return result generator.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -