Using disposables around sideeffects. #1161
-
Hello! I’m new to functional programming and having troubles when lazy evaluating a bunch of sideeffects combined with opentelemtry and measuring calls to a database etc. The lazy evaluation of my sideeffects of type Eff executes with a single run att the end of the declaration of all expressions. This results in all usings only covers the lazy init of each sideeffect, not the actual execution! Anyone have faced the same problem? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you're using disposables that have been created outside of an var openFile = Eff<FileStream>(() => File.OpenText(path));
use(openFile, stream => /* Eff expression that uses the stream */); |
Beta Was this translation helpful? Give feedback.
If you're using disposables that have been created outside of an
Eff
orAff
then you will need to force the evaluation of theEff
orAff
before disposing. Otherwise it's possible to lift disposables into theEff
orAff
expression, so they're run lazily too: