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
Post a Comment