You might have noticed that almost all of our examples are somewhat badly behaved. They open communication channels to the rest of the world and then
just leave them open. Also they fork plenty of processes (
#server) and never wait for them.
This would have been extremely redundant in this tutorial. But here – for the sake of completeness – pseudo-code for cleaning up, things you should also worry about:
channels.each do |channel| channel.close end Process.waitall
Cod is NOT thread-safe. This means that you simply need one communication channel per thread that wants to do communication. Which should be just a few, anyway.
The reason for this is plain when you look at the beanstalkd protocol – it is stateful. So even if cod was thread-safe, the connection it manages would still not be.
You’ve made it this far and read through my whole tutorial. Well, thanks, I guess. For all the fish.
Let me know what you think of all this. If I mistyped or miswrote something, let me know. Or better even, submit a pull request against the documentation.
Let us, together, create a new world of interconnected machines, talking day and night. And then go up in the mountains, and hide, and be quiet.