3
votes

I have a Yesod app, with a table in my database with a flag with three posible states (ToUse, Using, Used), bu default ToUse.

when a user click a button the flag in database change to Using, the idea is that after 10 minutes if the flag was not change to Used (operation that make another user with another button) the flag go back to ToUSe, the problem is that searching i can't find a method to delay the operation to edit my database and I'm not sure if it is possible in Yesod

Searching I find timeout library but if I understand right that library only stop the execution of a program don't delay his start

I try to use Control.Concurrent but, get the following error

testTimeOut = do     
  c1 <- atomically $ newTQueue
  C.forkIO $ do
    C.threadDelay (2 * 1000000)
    id <- runDB $ insert $ SubForm "ToUse"  10 
    atomically $ do 
      writeTQueue c1 "result 1" 

Couldn't match expected type ‘IO t0’ with actual type ‘HandlerT site0 IO (Key SubForm)’

EDIT

This code work form me

getFooR :: Handler RepHtml
getFooR = do
  runInnerHandler <- handlerToIO
  liftIO $ forkIO $ runInnerHandler $ do
    Code here runs inside GHandler but on a new thread.
    This is the inner GHandler.
    ...
  Code here runs inside the request's control flow.
  This is the outer GHandler.
  ...
1
timeout? Literally the first hit on Google for "Haskell timeout". If you didn't do that minimum effort, shame on you; if you did, you should say in your question why that isn't going to work. - Daniel Wagner
FWIW, you would want to use timeout from lifted-base in order to use it in a yesod handler: hackage.haskell.org/package/lifted-base-0.2.3.8/docs/…. - creichert
@DanielWagner if I understand right the documentation about timeout function they dont make a delay, they just stop the execution of a function if it exceeds n miliseconds; - oriaj
@oriaj Okay. Did you google for "Haskell delay"...? - Daniel Wagner
@DanielWagner yes and find Control.Concurrent I try to make and implantation but fail because the return have to be and IO, I edit my question with my code - oriaj

1 Answers

1
votes

I assume you are looking for forkHandler.