
On Mon, May 31, 2021 at 19:03 Mario Lang wrote:
Tristan Cacqueray
writes: On Mon, May 31, 2021 at 17:31 Mario Lang wrote:
Tristan Cacqueray
writes: It seems like it would be safer to use withCreateProcess instead of createProcess to ensure the process is not left unattended.
Maybe I am unimaginative, but it seems to me I can not use withCreateProcess as I need to read/write the Handles outside of the initialisation phase. It seems to me withCreateProcess would kill my external process once my initialisation function is done. Or do I misunderstand bracket somehow? AIUI, withCreateProcess always calls cleanupProcess once the action is done, right?
I guess you would have to replace `start'` with something like:
```haskell withEngine :: Time unit -> ... -> (Engine -> IO ()) -> IO () ```
And let your user provide the `Engine -> IO ()` callback.
Ahh, of course, push the problem up the caller chain :-) And I guess if that caller needs a sort of handle, it would do it with a channel to communicate with its action? I know I was asking for idiomatic code, and I am thankful for the pointer. Exception safety is clearly a good goal. But, I wonder, is limiting the API in such a way worth the trouble? It looks like this change would trigger a complete rewrite of the current module and all its clients. I'd like to be confident this is the right thing to do before doing that.
Beware I'm in the same boat and I can't tell if this is the right thing to do :-) I like the with... idiom because it is straighforward and it should not limit the API, users just need to provide a callback instead of binding to get the resource. Though it is more tedious to use from a REPL, where you need to prefix each input with `withEngine ... $ \engine -> ...`
Alternatively, perhaps the `managed` library can be used to get something closer to your existing `start'`, e.g.: http://hackage.haskell.org/package/managed-1.0.8/docs/Control-Monad-Managed....
Ahh, thanks again. I'll have to digest all of this.
Cheers, -Tristan