1 package App::Clifton::Task;
3 use Log::Contextual qw(:log);
7 extends 'App::Clifton::Component';
9 has on_finished => (is => 'rw');
11 has name => (is => 'ro', required => 1);
13 has body => (is => 'ro', required => 1);
15 has dependencies => (is => 'ro', default => sub { {} });
17 has merge_point => (is => 'lazy');
19 sub _build_merge_point { Async::MergePoint->new }
23 my $deps = $self->dependencies;
24 if (my @needs = keys %$deps) {
25 my $mp = $self->merge_point;
27 foreach my $key (@needs) {
28 $deps->{$key}->on_finished(sub { $mp->done($key => $_[0]) });
30 $mp->close(on_finished => $self->_capture_weakself('_schedule_body'));
32 $self->_schedule_body;
37 my ($self, %args) = @_;
38 my $fire_body = $self->_capture_weakself('_fire_body');
39 $args{on_finished} = $self->_finished_callback;
40 $self->_schedule(sub { $fire_body->(\%args); });
48 sub _finished_callback {
50 $self->_capture_weakself('_schedule_finished');
53 sub _schedule_finished {
54 my ($self, @args) = @_;
55 if (my $on_finished = $self->on_finished) {
56 $self->_schedule(sub { $on_finished->(@args) });
58 $self->parent->remove_child($self);
60 #warn Devel::FindRef::track $self;