1 # depends on: class.rb module.rb
4 # Continuation objects are generated by Kernel#callcc. They hold a return
5 # address and execution context, allowing a nonlocal return to the end of the
6 # callcc block from anywhere within a program. Continuations are somewhat
7 # analogous to a structured version of C's setjmp/longjmp (although they
8 # contain more state, so you might consider them closer to threads).
12 # arr = [ "Freddie", "Herbie", "Ron", "Max", "Ringo" ]
14 # puts(message = arr.shift)
15 # $cc.call unless message =~ /Max/
24 # This (somewhat contrived) example allows the inner loop to abandon
30 # for j in i*5...(i+1)*5
31 # cont.call() if j == 17
47 raise NoMethodError.new
50 def self.create(task=nil)
81 alias_method :[], :call
86 cont = Continuation.create
87 # Task#dup appears as though it returns nil in the dup'd
88 # task, kinda like fork().
89 task = Task.current.dup
97 module_function :callcc