Async Function with ES6 Generator

let’s say we want to find the first student’s home address, this is something we would do for fetching the data:

1. retrieve the list of the student in the class
2. retrieve the student’s address with the first result (from above)

since they are all connected, this is what the code looks like

Now let’s attach the generator

but this is not really what I want. I am writing a bunch of test and since test is a bit complicated, I would like to process the result inside the function, something like this

so here’s the final modification that suits my need

this way I can just keep writing my test case and put it in the testMaster() and that’s it.

Like what you read? Give Jim Kang a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.