module DelimCC

Public Instance Methods

abortcc(&blk) click to toggle source
# File lib/delimcc.rb, line 24
def abortcc(&blk)
    value = blk.call
    metacc_get.call value
end
metacc_get() click to toggle source
# File lib/delimcc.rb, line 10
def metacc_get
    tmp = Thread.current["__meta_cc__"]
    if !tmp
        proc { raise "not within a reset statement" }
    else
        tmp
    end
end
metacc_set(&meta_cont) click to toggle source
# File lib/delimcc.rb, line 19
def metacc_set(&meta_cont)
    Thread.current["__meta_cc__"] = meta_cont
end
reset(&blk) click to toggle source
# File lib/delimcc.rb, line 29
def reset(&blk)
    callcc do |cont|
        meta_cont = metacc_get
        metacc_set {|value|
            metacc_set &meta_cont
            cont.call value
        }
        abortcc &blk
    end
end
shift(&blk) click to toggle source
# File lib/delimcc.rb, line 40
def shift(&blk)
    callcc do |cont|
        abortcc do
            blk.call proc {|value|
                reset { cont.call value }
            }
        end
    end
end