Promises in D

Calvin P cloudlessapp at gmail.com
Thu Apr 8 05:44:15 UTC 2021


On Wednesday, 7 April 2021 at 16:43:59 UTC, Vladimir Panteleev 
wrote:
> You don't need an object pool at all with delegates. You can 
> just pass a slice of an array on the stack.

Yes, I cloud just free it.

> The paragraph you quoted discussed delegates, not promises. 
> Promises do need a copy always, as I stated in my post.

I think it depends on the Promise lifetime and the Caller 
lifetime.

In my code the buffer do copy at caller lifetime finished like 
scope exit or __dtor, or it need a bigger capability.

If the Promise outlive the caller lifetime, I can not pass caller 
delegate as reject/resolve because the caller cloud be destroyed, 
in this case The callback accepted a copy slice result( when 
caller destroy the buffer the copy take place).

If you can pass caller delegate to promise(the caller live), then 
you can pass slice to promise.  If the caller destroy before 
resolve/reject, then you code crashed or you need copy your 
template view.

A Buffer destroyed don't mean the memory is released, it can be 
moved into other instance, or hold by a Slice.





More information about the Digitalmars-d mailing list