tarcieri/cool.io
FreeSimple evented I/O for Ruby (but please check out Celluloid::IO instead)
FreeFree tier
About tarcieri/cool.io
Cool.io is an event-driven I/O library for Ruby, built on the high-performance libev library. It provides a cross-platform interface to system calls such as epoll (Linux), kqueue (BSD/macOS), and completion ports (Solaris). The library offers core classes for event loops and watchers (I/O, timer, stat, async) to build asynchronous applications. Additionally, Cool.io provides asynchronous wrappers for Ruby's core socket classes, including Cool.io::TCPSocket with buffered I/O and connection callbacks.
Key Features
Built on the libev event library for cross-platform high-performance I/O (epoll, kqueue, completion ports)
Cool.io::Loop class for event loop management using underlying system calls
Cool.io::Watcher base class with four types: IOWatcher, TimerWatcher, StatWatcher, AsyncWatcher
Watchers support attach/detach/disable/enable methods for flexible event monitoring
Asynchronous wrappers for Ruby socket classes including Cool.io::TCPSocket with write buffering and callbacks (connect, receive, drain)
Pros & Cons
Pros
- Leverages highly optimized system calls for efficient I/O multiplexing
- Cross-platform support (Linux, BSD/macOS, Solaris)
- Provides both low-level watchers and higher-level socket abstractions
- Open source with permissive license (MIT)
Best For
Building scalable event-driven network servers and clients in RubyAsynchronous file or directory monitoring using StatWatcherCross-thread signaling between event loops using AsyncWatcherCreating non-blocking TCP connections and data handling
FAQ
What is Cool.io?
Cool.io is an event-driven I/O library for Ruby, built on top of the libev library. It provides event loops and watchers to handle asynchronous I/O operations efficiently.
What types of watchers are available?
Cool.io includes IOWatcher (read/write events), TimerWatcher (one-shot or interval timers), StatWatcher (file/directory change monitoring), and AsyncWatcher (cross-thread signaling).
How do I use watchers?
Watchers can be attached to a Cool.io::Loop using attach(loop), detached with detach, or toggled with disable/enable. The evloop method returns the bound loop.
Does Cool.io support async socket operations?
Yes, Cool.io provides asynchronous wrappers like Cool.io::TCPSocket for non-blocking TCP connections with callbacks for connect, data receipt, and write completion.