Table of Contents

Waiting for data

Always the same thing with these mail boxes. No one ever writes.

  box = Cod.pipe, box)  # => nil

Hey, maybe someone dropped us an email?

  box = Cod.pipe
  mail = Cod.pipe.split
  mail.write.put 'an email'
  ready =, box: box, email:  

  ready.has_key?(:email)      # => true
  ready[:email] ==  # => true

Server structure: a big loop

The real message here is that cod can do something almost like a select(2), only better. It allows for freely mixing cod channels, common IO streams and implementors of the #to_read_fds message.

This means that your server can be built around a big loop. At the top of the loop you have a select on all your important channels, like this:

  loop do
    ready =, channel_hash)
    process_channel1 if ready.has_key? :channel1
    process_channel2 if ready.has_key? :channel2
    process_channel3 if ready.has_key? :channel3
    # ...

The select facility only works for checking if data is available on a channel. This makes sense, since cod channels are always ready for writing.


Currently, you cannot use beanstalk channels inside a We have ideas on how to change this and might get around to it sometime soon.