Created
March 25, 2012 01:40
-
-
Save mwotton/2190651 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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