Reputation: 8433
I was wondering, could somebody give an example how to start threads from inside a Yesod handler?
I want something like this:
User goes to mypage.com/create, which is the Yesod route CreateR
User POSTS by pushing a button on the page
The POST handler for CreateR forks a new thread, then redirects the user to some "success" page.
The thread continues to run in the background, altering STM variables which other handlers will access.
I was using liftIO, but it was crashing with the following error:
Exit code: ExitFailure 139
The documentation says something about resourceForkIO, but I can't get the types to work, since I have no idea where/how to use that function.
Upvotes: 1
Views: 410
Reputation: 4906
I do it all the time, especially for long running tasks:
liftIO $ forkIO $ customizerJob cnStr env
I do not use ResourceT or any TVars to exchange information and progress. Rather i use tables in db. Very simple, does not require arcane knowledge of haskell monad transformers and STM :)
Upvotes: 2