Promises in D
Calvin P
cloudlessapp at gmail.com
Thu Apr 8 05:53:44 UTC 2021
On Thursday, 8 April 2021 at 05:44:15 UTC, Calvin P wrote:
> 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.
The pointer is If the caller want provide memory to promise pass
a buffer or slice instead array. Then the caller can control the
lifetime of the buffer/slice.
And the buffer always get copy then the buffer/slice lifetime
finished.
If this in a single thread event loop, then the buffer/slice
destroy code will make sure the resource will be available for
the promise object by made a copy. (or not copy if the caller
owned stack array still live when promise resolved/rejected.)
More information about the Digitalmars-d
mailing list