New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a fast-reload ghcid based development server #33

Merged
merged 5 commits into from May 19, 2018

Conversation

Projects
None yet
3 participants
@parsonsmatt
Owner

parsonsmatt commented May 19, 2018

This PR implements a new REPL command:

$ make ghcid-devel

Which loads the servant-persistent application in a background thread. When you edit your files or change anyhting, the server process is killed and restarted in GHCi, so it is lightning fast compared to a full stack build and linking all the executables.

parsonsmatt added some commits May 19, 2018

@parsonsmatt

How to add GHCi persistent server to your servant app

--command "stack ghci servant-persistent" \
--test "DevelMain.update"

.PHONY: ghcid-devel help

This comment has been minimized.

@parsonsmatt

parsonsmatt May 19, 2018

Owner

Every project should have a Makefile! They're so useful for providing short little commands that you'll want to use frequently.

module Main where

import qualified Control.Monad.Metrics as M

This comment has been minimized.

@parsonsmatt

parsonsmatt May 19, 2018

Owner

Most of this code was ripped out and moved into a Init module to be shared.

@@ -0,0 +1,108 @@
{-# LANGUAGE OverloadedStrings #-}

This comment has been minimized.

@parsonsmatt

parsonsmatt May 19, 2018

Owner

This file was largely copied from the Yesod scaffolding.

, ekg
, ekg-core
, fast-logger
, foreign-store

This comment has been minimized.

@parsonsmatt

parsonsmatt May 19, 2018

Owner

Most of the dependencies are just sorted alphabetically, but this one is real. We use it to persist state in GHCi between reloads.

@bitemyapp

This comment has been minimized.

bitemyapp commented May 19, 2018

This is a good application of the app/DevelMain.hs thing from the Yesod scaffolds.

@parsonsmatt parsonsmatt merged commit eaa45d7 into master May 19, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
-> IO ThreadId
start done = do
(port, config, app) <- initialize
forkIO (finally (runSettings (setPort port defaultSettings) app)

This comment has been minimized.

@k0001

k0001 May 21, 2018

You probably want to use forkFinally. Check the mask and forkIO section here: https://www.safaribooksonline.com/library/view/parallel-and-concurrent/9781449335939/ch09.html

This comment has been minimized.

@parsonsmatt

parsonsmatt May 21, 2018

Owner

Good call! I'll open an issue on the Yesod template, since it's copied from there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment