Open kirkshoop opened 4 months ago
I don't think returning the operation state would help - I think this would just move the allocation responsibility to the caller. The operation state needs to live somewhere that outlives the entire call stack (an interrupt). That's the job of the static_allocator
at the moment.
(Admittedly, It might be that returning an optional<StopSource*>
is of limited use too - we might want instead to access the stop source through the same type tag used for the call to start_detached
.)
Delegating to the caller means that the result can stored in a global optional var. this guarantees the lifetime and removes the allocation.
I built start_now() as a replacement for start_detached() This shows how the return value can be used to remove the allocation..
change the object returned by start_detached from
optional<StopSource*>
to an immovable object that hasrequest_stop()
the immovable object constructor will connect and start the sender.
request_stop
will forward to thestop_src
If needed, a copyablestop_ref
type can store a pointer to the immovable object and forward calls to itsrequest_stop
to the immoveable object.