Iterating and the Asynchronous Loop

This lesson shows how to iterate with asynchronous loops.

Iteration and the TypeScript generator

TypeScript generators are an advanced and very modern concept. They use the function* syntax which is the standard function keyword followed by an asterisk. The star syntax indicates that a function returns a generator object. A function that returns a generator object can return multiple times. This function allows the use of the yield keyword, which returns a value without returning the function. It allows for potential infinite iteration, while still being able to consume the value outside the function. The function returns a generator object which has a .next() function. The next function returns a value of type IteratorResult. The function returns when the iteration is over with a done property from IteratorResult. The done property is of type Boolean and is used to tell a while or for loop to stop.

Get hands-on with 1400+ tech skills courses.