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
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.
When
?
exits early, it does so using variationsreturn v
- however, in frameworks such aschronos
, we need to changereturn v
tofuture.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 calledreturnResult
, and it would be responsible for breaking the control flow (performing thereturn
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.