Async Iterators for Big Data Sets

August 2, 2018 comments 106 Reads

Iterators are great for looping through data sets. If you have an array then it has a built-in iterator. Objects can have a custom iterator built for them.
What if your dataset is too big to fit inside your Array? What if it takes up too much memory? With an Asynchronous Iterator you can load the data in chunks.
The for…of loop will have an await capability soon. However, we can already mimic the behaviour by creating an asynchronous function and calling it recursively.
Code GIST: https://gist.github.com/prof3ssorSt3v3/140e940c4c207ce0a5106b7b0d8fc12a
IIFE video: https://www.youtube.com/watch?v=Xd7zgPFwVX8