Skip to content

Instantly share code, notes, and snippets.

@mwotton
Created March 25, 2012 01:40
Show Gist options
  • Save mwotton/2190651 to your computer and use it in GitHub Desktop.
Save mwotton/2190651 to your computer and use it in GitHub Desktop.
module DateAndTime(DateData(..), rulemap) where
import Control.Concurrent(forkIO, threadDelay, ThreadId)
import Control.Monad(forever)
import Types
import qualified Data.ByteString.Char8 as BS
data Date = Date
data PeriodData = PeriodData { seconds :: Int }
data DateData = DateData { time :: Date }
periodically :: PeriodData -> IO () -> IO (Maybe ThreadId,BS.ByteString)
periodically incoming action = do
pid <- forkIO $ forever (threadDelay (seconds incoming) >> action)
return (Just pid, "ok")
oneTime :: DateData -> IO () -> IO (Maybe ThreadId,BS.ByteString)
oneTime incoming action = do
pid <- forkIO $ waitUntil (time incoming) >> action
return (Just pid, "ok")
waitUntil :: Date -> IO ()
waitUntil = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment