Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I not allowed to break a Promise?

The following simple Promise is vowed and I am not allowed to break it.

my $my_promise = start {
    loop {}   # or sleep x;
    
    'promise response'
}

say 'status : ', $my_promise.status;      # status : Planned

$my_promise.break('promise broke');       # Access denied to keep/break this Promise; already vowed
                                          # in block <unit> at xxx line xxx

Why is that?

like image 721
jakar Avatar asked Oct 05 '20 16:10

jakar


People also ask

Why is it not okay to break a promise?

Broken promises can harm your relationship since doing so can make your partner lose their trust in you. Moreover, frequently breaking your promises can also make your partner consider you as someone who doesn't keep their word, affecting your relationship as a whole.

Is it ever OK to break a promise?

First, let's be clear, breaking promises due to being lazy, fearful, or flaky is a personality flaw, and it has consequences. However, if the harm caused by breaking a promise would be less than the harm caused by keeping it, we're morally obligated to break the promise.

Why is it important to keep your promises to others?

Promises are commitmentsPeople with strong relationships rank higher in emotional intelligence and are more likely to stay loyal to their commitments. Whether the commitment is to yourself or to someone else, making a promise is a commitment that you will keep your word. It is a commitment that reinforces trust.

Why do people make promises they can't keep?

Sometimes we make promises we can't keep. We make them because they seem kinder than the alternative. We don't want to deny people their wishes or tell someone that the thing they want is impossible.


1 Answers

Because the Promise is vowed, you cannot change it: only something that actually has the vow, can break the Promise. That is the intent of the vow functionality.

What are you trying to achieve by breaking the promise as you showed? Is it to stop the work being done inside of the start block? Breaking the Promise would not do that. And the vow mechanism was explicitly added to prevent you from thinking it can somehow stop the work inside a start block.

If you want work inside a start block to be interruptible, you will need to add some kind of semaphore that is regularly checked, for instance:

my int $running = 1;
my $my_promise = start {
    while $running {
        # do stuff
    }
    $running
}

# do other stuff
$running = 0;
await $my_promise;

Hope this made sense.

like image 198
Elizabeth Mattijsen Avatar answered Jan 20 '23 15:01

Elizabeth Mattijsen