In this video, Josh McQuiston demonstrates how to combine multiple coroutines into one single data processing pipeline. Learn how the ability of the coroutine to both receive and send data can be built into efficient and powerful tools that are easily reusable and pluggable, and can branch to multiple targets.
- [Narrator] I've mentioned already that it is possible…for a single coroutine to both send and receive values.…Similar to the pipelines I've showed you with generators…earlier in the course,…coroutines can also be used to create data pipelines.…I've opened up 0305 router pipeline…from the exercise files.…In this file there are two coroutines…called router and file_write.…These are set up to work in line.…I can send data initially to the router coroutine.…
The router coroutine is able to do something…that generators are not able to do.…It both receives data and sends it.…The router coroutine can branch in more than one direction…and send to multiple targets.…This coroutine will take the lines from the names file,…split it into first and last names,…and then send each one to a different target.…The two targets are simply separate instanciations…of the file_write coroutine.…Coroutines are able to do this because the whole process…is being driven from the beginning.…
Data is being pushed through the pipeline,…rather than pulled like it was with generator pipelines.…
Share this video
Embed this video
Video: Coroutine pipelines