Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do hot code reload when developing with Cowboy?

Tags:

vi

erlang

cowboy

I'm developing with Cowboy and erlang.mk and currently my flow is : 1. change code in vi, save, run make 2. close Cowboy, start Cowboy again (i'm running Cowboy in console mode for tracing/debugging purposes)

Is there a way to make Cowboy reload and restart itself automatically with as little lag as possible? I understand I could add Cowboy stop and start to my makefile but maybe there is a better/more responsive way?

I saw there is sync package from rustyio but it seems overly complicated to have to hook it into my app directly.

like image 249
voltaire Avatar asked Dec 17 '14 21:12

voltaire


People also ask

What is hot code reload?

The hotCodeReloading option enables special compilation mode where changes in the code can be applied automatically to a running program. The code reloading happens at the granularity of an individual module.

How does Javascript hot reload work?

Hot reloading allows you to see the changes that you have made in the code without reloading your entire app. Whenever you make any changes, all you need to do is save your code. As soon as you save your code, React Native tracks which files have changed since your last saved, and only reload those file for you.


1 Answers

I use rebar all the time. In rebar.config, I have

 {deps,[
        {sync,         ".*", {git, "git://github.com/rustyio/sync", {tag,"master"}}},
 }

I use a .erlang file, typically placed in src/.erlang with the following two lines

 code:add_path("../deps/sync/ebin").
 sync:go().

Now, whenever I save a file, it is reloaded. I see no reason why this shouldn't work for Cowboy

like image 118
mattias Avatar answered Sep 30 '22 18:09

mattias