Friday 21 April 2017

NodeJs - Yield FindOne

I'm learning NodeJs/Javascript and wanted to create a for/while loop that includes an asynchronous call on the database. Such as

do {

    id = models.Cage.generateTemporaryId();
    let cage = yield models.Cage.findOne({ temporaryId: id });

} while( cage ); 

I understood the "yield" keyword will cause execution to be paused until the promise is resolved but I merely get a syntax error. Have I misunderstood? If I remove the "yield" keyword it fixes the syntax error.

Any pointers are appreciated.



via prime

No comments:

Post a Comment