Project

keeper

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A thread-safe blocking event pattern for your pleasure.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 1.5.1
~> 2.1.0
~> 0.6.0
 Project Readme

Keeper!?

Ever wished you could spawn several threads, each of them waiting for a certain event to happen, without having to do the manual book-keeping of condition variables and mutexes? Now you can!

Keeper is a library that allows multiple threads to wait for incoming events. Have a look at this example code from the docs:

events = Keeper::Keeper.new

[:pang, :boom, :pow].each_with_index do |event, i|
  this_many = i + 1
  this_many.times do |i|
    Thread.new do
      events.wait_for(event)
      puts "#{event}:#{i}!"
      events.fire(event == :pang ? :boom : :pow)
    end
  end
  puts "#{this_many} threads waiting for #{event}"
end

print "Pause for effect"
3.times { sleep 1 and print "." }
puts

events.fire(:pang)
Thread.list.reject { |th| th == Thread.current }.map(&:join)

And here’s your output:

1 threads waiting for pang
2 threads waiting for boom
3 threads waiting for pow
Pause for effect...
pang:0!
boom:0!
boom:1!
pow:0!
pow:2!
pow:1!

Ain’t that awesome?! I think it is.

License

X11. It means you can use Keeper for whatever you want as long as you ship the license text with it, it’s in LICENSE.txt.