Joey Eremondi
Joey Eremondi

Reputation: 8433

Creating a new thread in a Yesod handler

I was wondering, could somebody give an example how to start threads from inside a Yesod handler?

I want something like this:

  1. User goes to mypage.com/create, which is the Yesod route CreateR

  2. User POSTS by pushing a button on the page

  3. The POST handler for CreateR forks a new thread, then redirects the user to some "success" page.

  4. 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

Answers (1)

Vagif Verdi
Vagif Verdi

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

Related Questions