socketry/cool.io logo

socketry/cool.io

Free

Simple evented I/O for Ruby (but please check out Celluloid::IO instead)

FreeFree tier
Type
Open Source

About socketry/cool.io

Cool.io is an event-driven I/O library for Ruby, built on the high-performance libev event library. It provides cross-platform support for system calls such as epoll (Linux), kqueue (BSD/macOS), and completion ports (Solaris). The library offers a simple API with core classes like Cool.io::Loop for the event loop and Cool.io::Watcher for observing events. It includes several watcher types: IOWatcher (for readable/writable I/O), TimerWatcher (for timed events), StatWatcher (for file/directory monitoring), and AsyncWatcher (for cross-thread signaling). Additionally, Cool.io provides asynchronous wrappers for Ruby's socket classes, including Cool.io::TCPSocket with buffered I/O and non-blocking connect. Note: the project's GitHub description suggests checking out Celluloid::IO as an alternative.

Key Features

Built on the high-performance libev event library providing cross-platform evented I/O (epoll, kqueue, completion ports)
Core classes: Cool.io::Loop (event loop) and Cool.io::Watcher (event observer base)
Four watcher types: IOWatcher, TimerWatcher, StatWatcher, and AsyncWatcher for flexible event handling
Asynchronous wrappers for Ruby socket classes, including Cool.io::TCPSocket with buffered I/O and non-blocking connect
Watchers support attach, detach, enable, disable, and evloop methods for lifecycle management

Pros & Cons

Pros
  • High performance through native system calls (epoll, kqueue) via libev
  • Cross-platform compatibility across Linux, BSD, macOS, and Solaris
  • Simple and clear API for event-driven programming in Ruby
  • Includes asynchronous wrappers for Ruby's core socket classes to simplify non-blocking I/O
Cons
  • Ruby-specific; not usable from other languages
  • Project may be superseded by Celluloid::IO, as noted in the repository description
  • Limited documentation beyond the basic README

Best For

Building asynchronous event-driven network servers in RubyReal-time monitoring of files or directories for changesCross-thread signaling within event loopsNon-blocking TCP client connections with buffered writing

FAQ

What types of watchers does Cool.io provide?
Cool.io provides four watcher types: IOWatcher (waits for I/O events), TimerWatcher (waits for time-based events), StatWatcher (monitors file/directory changes), and AsyncWatcher (wakes a different thread's event loop).
Does Cool.io support non-blocking TCP connections?
Yes, Cool.io::TCPSocket provides a buffered wrapper around Ruby's Socket class with a connect method for asynchronous outgoing TCP connections and write buffering to prevent blocking.