Christopher Pitt Software Developer

Cooperative Multitasking with Generators

Last updated on 6th April 2024

One day, while staring out the window at all the async/await languages playing ball, I wondered what it would take to do the same in PHP. This talk became the answer to that question.

Many languages support the idea of generators, but fewer support the idea of async/await. Turns out they are closely related. Generators are just a fancy way to “get the next item when I need it”. What if we use them to “get the next instruction when I need it”?

With this slight change to our thinking, we can build a functional async/await model in any language with generators.