Skip to content

Internal Classes

Jiang Jinyang edited this page Jan 1, 2018 · 2 revisions

Core classes and modules

See documentation

LightIO::Beam

Beam is a fiber-based lightweight executor. Beam scheduled on IO operations and transfer back when IO is ready, so in most cases we can use beams to instead threads to gain better performance.

LightIO::Watchers::IO

Watchers::IO is a way to make beams collaborate with 'raw' ruby socket / io objects.

watcher = Watchers::IO.new(socket, :r)
watcher.wait_read
socket.read_nonblock(4096)
watcher.close

watcher.wait_read will trigger a beam schedule, you must invoke Watchers::IO#wait_read or Watchers::IO#wait_write before actually read or write socket, otherwise all beams will blocking until socket is readable/writeable.

See echo server example

LightIO::Library

LightIO::Library provide Beam compatible libraries, LightIO::Library include same name classes or methods in ruby stdlib, for example use LightIO::Library::Queue to instead Queue from stdlib. You can access LightIO::Library classes from LightIO namespace for convenient, like LightIO::Timeout.timeout.

Clone this wiki locally