Created
December 26, 2012 15:38
-
-
Save anonymous/4380959 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
class Task { | |
has &!callback; | |
has Task @!dependencies; | |
has Bool $.done; | |
method new(&callback, Task *@dependencies) { | |
return self.bless(*, :&callback, :@dependencies); | |
} | |
method add-dependency(Task $dependency) { | |
push @!dependencies, $dependency; | |
} | |
method perform() { | |
unless $!done { | |
.perform() for @!dependencies; | |
&!callback(); | |
$!done = True; | |
} | |
} | |
} | |
my $eat = | |
Task.new({ say 'eating dinner. NOM!' }, | |
Task.new({ say 'making dinner' }, | |
Task.new({ say 'buying food' }, | |
Task.new({ say 'making some money' }), | |
Task.new({ say 'going to the store' }) | |
), | |
Task.new({ say 'cleaning kitchen' }) | |
) | |
); | |
$eat.perform(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment