Last active
July 21, 2018 09:42
-
-
Save airled/648c5b182ec672f075020c585a50f692 to your computer and use it in GitHub Desktop.
Naive promise implementation
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
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