Table of Contents

Waiting for data

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


  box = Cod.pipe
  
  Cod.select(0.1, box)  # => nil

Hey, maybe someone dropped us an email?


  box = Cod.pipe
  mail = Cod.pipe.split
  
  mail.write.put 'an email'
  
  ready = Cod.select(0.1, box: box, email: mail.read)  

  ready.has_key?(:email)      # => true
  ready[:email] == mail.read  # => 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 = Cod.select(nil, channel_hash)
    
    process_channel1 if ready.has_key? :channel1
    process_channel2 if ready.has_key? :channel2
    process_channel3 if ready.has_key? :channel3
    
    # ...
  end

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.

Limitations

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