Promise resolve

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Promise resolve

patrick.rein
Hi everyone,

during a project some students recently used Promise objects a lot. Due to the nature of the project, they often wanted to resolve a Promise without a value. As there is no #resolve method they resorted to `resolveWith: nil`. As this is rather ugly, I would like to propose an additional (convenience) method #resolve which simply resolves the Promise with the value nil. This would also mirror the #then: protocol as the resolve block does not have to accept the argument passed by the promise.

A downside of this proposal is that the protocol of Promise is currently quite lean and the method does not add anything substantial.

Bests
Patrick

Reply | Threaded
Open this post in threaded view
|

Re: Promise resolve

marcel.taeumel
Sounds good. There are many classes in Squeak with similar convenience messages. 

+1

Best,
Marcel

Am 14.12.2018 10:12:10 schrieb [hidden email] <[hidden email]>:

Hi everyone,

during a project some students recently used Promise objects a lot. Due to the nature of the project, they often wanted to resolve a Promise without a value. As there is no #resolve method they resorted to `resolveWith: nil`. As this is rather ugly, I would like to propose an additional (convenience) method #resolve which simply resolves the Promise with the value nil. This would also mirror the #then: protocol as the resolve block does not have to accept the argument passed by the promise.

A downside of this proposal is that the protocol of Promise is currently quite lean and the method does not add anything substantial.

Bests
Patrick



Reply | Threaded
Open this post in threaded view
|

Re: Promise resolve

David T. Lewis
It sounds like a reasonable convenience method.

I am curious though - in what case is there an instance of Promise
that should not be resolved with an actual value? By definition, a
Promise represents the result of a (future) method evaluation. I would
expect that in normal use, the value of the Promise would be nil if
and only if the future evaluation answers nil.

But maybe we have instances of Promise that cannot or will not be
evaluated normally, and we just need to clean them up?

Dave

On Fri, Dec 14, 2018 at 10:15:34AM +0100, Marcel Taeumel wrote:

> Sounds good. There are many classes in Squeak with similar convenience messages.??
>
> +1
>
> Best,
> Marcel
> Am 14.12.2018 10:12:10 schrieb [hidden email] <[hidden email]>:
> Hi everyone,
>
> during a project some students recently used Promise objects a lot. Due to the nature of the project, they often wanted to resolve a Promise without a value. As there is no #resolve method they resorted to `resolveWith: nil`. As this is rather ugly, I would like to propose an additional (convenience) method #resolve which simply resolves the Promise with the value nil. This would also mirror the #then: protocol as the resolve block does not have to accept the argument passed by the promise.
>
> A downside of this proposal is that the protocol of Promise is currently quite lean and the method does not add anything substantial.
>
> Bests
> Patrick
>

>


Reply | Threaded
Open this post in threaded view
|

Re: Promise resolve

Bert Freudenberg
On Fri, Dec 14, 2018 at 6:30 PM David T. Lewis <[hidden email]> wrote:
It sounds like a reasonable convenience method.

I am curious though - in what case is there an instance of Promise
that should not be resolved with an actual value? 

When you use that computation for its side-effects.

That is, chaining a series of actions in time can be done using promises, but the value passed is irrelevant.

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: Promise resolve

David T. Lewis
On Fri, Dec 14, 2018 at 06:47:30PM -0800, Bert Freudenberg wrote:

> On Fri, Dec 14, 2018 at 6:30 PM David T. Lewis <[hidden email]> wrote:
>
> > It sounds like a reasonable convenience method.
> >
> > I am curious though - in what case is there an instance of Promise
> > that should not be resolved with an actual value?
> >
>
> When you use that computation for its side-effects.
>
> That is, chaining a series of actions in time can be done using promises,
> but the value passed is irrelevant.
>
> - Bert -

Thanks, that makes sense.

And +1 for the update.