Skip to content

Conversation

@CMCDragonkai
Copy link
Member

@Zachaccino @nzhang-zh can you help flesh this out?

@CMCDragonkai
Copy link
Member Author

I've cleaned this up and now have 2 executables produced from a nix-build ./release.nix --attr application.

This demonstrates how to use Warp with monad-logger and safe-exceptions and the ReaderT application transformer pattern, and also the usage of data-default-class.

The way I get the env variables applied to the default parameters is a bit bulky, I think there's a better way to do it.

I want to mention that I realized that warp uses IO at the end instead of MonadIO. Which sort of means that once you go into the warp context, you can't really use the same logging context as the others. Instead we end up "unwrapping" the logging immediately in IO. And this sort of makes sense in that the handling of a request happens in IO anyway, and at that point the logging code would have to be executed and directed to a particular exit point. This is currently hardcoded as runStderrLoggingT. It may be possible to put this function as part of the DemoEnv, so that way the ReaderT itself dictates where this will be, and then we would "ask" for the function and inject it into our warpApp.

@ksenia-portu @nzhang-zh @Zachaccino please review this code.

I'm merging this.

@CMCDragonkai CMCDragonkai merged commit acd289d into master Mar 10, 2020
@CMCDragonkai
Copy link
Member Author

Oh and cabal v2-repl is pretty useful. Make sure to use :m *Demo to get into the module context instead of :m +Demo which just "imports" the module.

@CMCDragonkai CMCDragonkai deleted the service branch March 10, 2020 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants