Ralph
Ralph

Reputation: 32294

Running service in futures in Yesod

In the Scala Play Framework, it is advised that long-running processes like database accesses be done in futures (Future) because there are a limited number of worker threads listening to web requests. This is commonly done by wrapping the processes in Future { ... } and having the methods return Future[SimpleRequest].

Should I being do something similar in Yesod? If so, how?

I understand the Haskell (GHC) has very light-weight threads ("sparks"). Does Yesod launch each request in a separate spark?

Upvotes: 2

Views: 107

Answers (1)

Michael Snoyman
Michael Snoyman

Reputation: 31335

Each Yesod request runs in its own green thread (sparks actually mean something else in GHC-land, but it sounds similar to what you're used to from Scala). That thread will terminate when the connection with the client terminates. If you want something to outlive that thread, use forkIO or- far better in my opinion- use the async package.

Upvotes: 4

Related Questions