Last active
August 29, 2015 14:06
-
-
Save stujo/f83a85e84e41598ae6c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Continuation - http://www.ruby-doc.org/core-2.1.3/Continuation.html | |
require 'continuation' | |
# class Continuity | |
# def initialize total | |
# @total = 5 | |
# end | |
# def next | |
# end | |
# end | |
# cont = Continuity.new(5) | |
# puts "1:#{cont.next}" | |
# puts "2:#{cont.next}" | |
# puts "3:#{cont.next}" | |
x = 0 | |
puts "A#{x} on #{Thread.current}" | |
c = callcc { |cc| puts "c on #{Thread.current}"; cc } | |
puts "B#{x} on #{Thread.current}" | |
d = callcc { |cc| puts "d on #{Thread.current}"; cc } | |
puts "C#{x} on #{Thread.current}" | |
x += 1 | |
puts "D#{x} on #{Thread.current}" | |
if c | |
puts "Calling c #{c} on #{Thread.current}" | |
c.call | |
else | |
puts "Not Calling c #{c} on #{Thread.current}" | |
end | |
if d | |
puts "Calling d #{d} on #{Thread.current}" | |
d.call | |
else | |
puts "Not Calling d #{d} on #{Thread.current}" | |
end | |
puts "EOF on #{Thread.current}" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Continuation - http://www.ruby-doc.org/core-2.1.3/Continuation.html | |
require 'continuation' | |
puts "START" | |
c = nil | |
i = 0 | |
callcc do |cc| | |
puts "c on #{Thread.current} #{cc}" | |
c = cc | |
end | |
puts "REPEAT-#{i}" | |
i+= 1 | |
c.call if i < 10 | |
puts "EOF" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment