Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (26 sloc) 757 Bytes

Deferrable

Deferrable provides a simple way to defer execution of a block without starting another process or thread.

Usage:

class Foo
  include Deferrable

  def bar(opts = {})
    deferred do
      # do something later
    end

    now_and_later do
      # do something now and when deferred blocks are executed
      # this could be useful for cache invalidations... yum
    end
  end

  def later
    complete_deferred # executes all deferred blocks in order
  end

  def nevermind
    clear_deferred # don't execute the deferred blocks after all
  end
end

Install:

gem install deferrable

License:

Copyright © 2009 Justin Balthrop, Geni.com; Published under The MIT License, see LICENSE