Skip to content

Instantly share code, notes, and snippets.

Created December 26, 2012 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4380959 to your computer and use it in GitHub Desktop.
Save anonymous/4380959 to your computer and use it in GitHub Desktop.
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