Where to add 'always running' thread to Yesod applications

江枫思渺然 提交于 2019-12-08 00:31:27

问题


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

Where is the correct place to splice in a fork, such that this work seamlessly, regardless of whether my app is running in 'yesod devel' or deployed for production.

P.S. I really just want to add a pseudo-Main, which will be forked (at service start) by whichever webserver runs the app through WAI.


回答1:


You should put it in the makeApplication function in the scaffolded Application.hs file.

This function will run once for every instance of your web application that is started1, and since you almost always only run one instance of your application, this is the place that you should do it.

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



来源:https://stackoverflow.com/questions/10969734/where-to-add-always-running-thread-to-yesod-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!