status-im / nim-stew

stew is collection of utilities, std library extensions and budding libraries that are frequently used at Status, but are too small to deserve their own git repository.
139 stars 18 forks source link

result: add result assignment extenstion point for `?` #134

Closed arnetheduck closed 9 months ago

arnetheduck commented 2 years ago

When ? exits early, it does so using variations return v - however, in frameworks such as chronos, we need to change return v to future.complete(v) - this feature allows chronos to inject a template that performs this assignment instead of using the "ordinary" flow.

Risk:

assignResult might already be taken as a name, and multiple frameworks might compete for the functionality.

Potential alternative:

Instead of assignResult, this construct could be called returnResult, and it would be responsible for breaking the control flow (performing the return in addition to assigning the result).

Other interactions:

https://github.com/status-im/nim-stew/pull/34 proposes a general-purpose conversion framework - this could be used to automatically convert the error based on existing conversions - the use case is that oftentimes, one error needs to be converted to another in a call chain and injecting a converter simplifies this flow - this might however create an problematic interaction with an assignResult template in the future.

arnetheduck commented 1 year ago

marking draft for now - failing in 2.0

arnetheduck commented 9 months ago

obsoleted by https://github.com/arnetheduck/nim-results/pull/37