Wednesday, March 16, 2016

Async patterns in javascript

Generators (Yield) 

The generator will pause itself and the iterator will resume it.  It can start and stop infinite number of time.

function* gen(){
    console.log("Hello");
    //The function will resume itself waiting for the next iterator
    yield null;
    console.log("World");
}

var it=gen();
it.next();   //prints "Hello"
it.next();   //print  "World"










No comments:

Post a Comment