Introducing the X Threads gem

require 'xthreads'

xthreads = XThreads.new
t1 = xthreads.create_loop('a', interval: 6) {puts 'fun fun fun'}
t1.start

#=> fun fun fun
# 6 seconds later ...
#=> fun fun fun

t1.stop
#=> 'a' stopping ...
#=> stopped


The X Threads gem is an experimental gem for handling threads more objectively, without relying upon another object class to manage state. It currently only supports creating threads with loops as this is typically what I use threads for.

In this example a timer is created which prints 'fun fun fun' every 6 seconds until the thread is stopped by a stop command.

Resoures: - jrobertson/xthreads - GitHub [github.com]

Tags:
Source:
1309hrs.txt
Published:
12-01-2012 13:09