Skip to content

Instantly share code, notes, and snippets.

@airled
Last active July 21, 2018 09:42
Show Gist options
  • Save airled/648c5b182ec672f075020c585a50f692 to your computer and use it in GitHub Desktop.
Save airled/648c5b182ec672f075020c585a50f692 to your computer and use it in GitHub Desktop.
Naive promise implementation
class Promise
def initialize(&blk)
@functions = [blk]
end
def then(&blk)
@functions << blk
end
def run
Thread.new(@functions) do |fs|
last_result = nil
until fs.empty?
last_result = fs.shift.(last_result)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment