Created
March 9, 2011 02:50
-
-
Save carlosbrando/861599 to your computer and use it in GitHub Desktop.
Exemplo de uso de Continuations
This file contains hidden or 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
#!/usr/bin/env ruby -wKU | |
require "continuation" | |
def my_method | |
callcc { |continuation| puts "Dentro do callcc"; return continuation } | |
puts "De volta ao método" | |
end | |
number = 1 | |
puts "Antes do método" | |
continuation = my_method | |
puts "Depois do método" | |
puts "Número: #{number}" | |
number += 1 | |
continuation.call if continuation | |
puts "Fim" | |
# Antes do método | |
# Dentro do callcc | |
# Depois do método | |
# Número: 1 | |
# De volta ao método | |
# Depois do método | |
# Número: 2 | |
# Fim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment