Where to add the "always works" thread in Yesod applications

I am writing a Yesod application, but it also needs to deploy several non-web services. (UDP listeners, TCP listening port, etc.)

Where is the right place for splice in the fork so that this work is uninterrupted, regardless of whether my application works in yesod devel or deployed for production.

Thanks,

Chris.

PS I just want to add a pseudo-Main, which will fork (when the service starts) by any web server that starts the application through WAI.

+2
source share
1 answer

You must put it in the makeApplication function in the Application.hs swap file.

This function will run once for each instance of your web application that runs 1, and since you almost always use only one instance of your application, this is the place you have to make.

1 Note that it is theoretically possible to run multiple instances of the same WAI application in the same process, for example. if you want two instances to listen on different ports, but by default this will never happen.

+3
source

Source: https://habr.com/ru/post/1480435/


All Articles