Steve Klabnik - cool event driven programming for Ruby

It seems like there is a common pattern with many libraries: You have your full stack solution, and then you have your lean and mean one. Ruby on Rails has its counterpart in Sinatra, for example. So what about event-driven programming frameworks, like EventMachine or Node.js?


require 'rubygems'
require ''

ADDR = ''
PORT = 4321 ADDR, PORT do
  on_connect do
    puts "#{remote_addr}:#{remote_port} connected"

  on_close do
    puts "#{remote_addr}:#{remote_port} disconnected"

  on_read do |data|
    write data

puts "Echo server listening on #{ADDR}:#{PORT}"

Pretty cool. is trying to make evented programming really easy, which is good, because this style of programming is a bit different than your usual kinds of web programming.

Under the hood, is built on top of libev, which hooks it up to various system calls on different operating systems for doing this kind of thing in a blazing fast manner. Then again, my OS developer buddies would kill me for calling a system call ‘performant,’ but that’s a different story… what it boils down to is that doesn’t reinvent the wheel: epoll on Linux, kqueue on BSD and OSX…

Personally, I’ve been meaning to write some software in the evented style, but I haven’t had the time to appropriately level up my Javascript skills yet. just might be the ticket to building something more than just a toy example or two.

[Github] [README]


Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00