Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bring Promise up to spec wrt keep/break
  • Loading branch information
lizmat committed Sep 17, 2014
1 parent 46a0d29 commit 0c54522
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/core/Promise.pm
Expand Up @@ -54,7 +54,11 @@ my class Promise {
$vow
}

method keep(Promise:D: \result) {
proto method keep(|) { * }
multi method keep(Promise:D:) {
self.vow.keep(True)
}
multi method keep(Promise:D: \result) {
self.vow.keep(result)
}

Expand All @@ -68,15 +72,19 @@ my class Promise {
$!result
}

method break(Promise:D: $result) {
self.vow.break($result)
proto method break(|) { * }
multi method break(Promise:D:) {
self.vow.break(False)
}
multi method break(Promise:D: \result) {
self.vow.break(result)
}

method !break($result) {
method !break(\result) {
$!lock.protect({
$!result = nqp::istype($result, Exception)
?? $result
!! X::AdHoc.new(payload => $result);
$!result = nqp::istype(result, Exception)
?? result
!! X::AdHoc.new(payload => result);
$!status = Broken;
self!schedule_thens();
$!cond.signal_all;
Expand Down

0 comments on commit 0c54522

Please sign in to comment.