Fwd: [Haskell-cafe] Fuzzy time deltas
Alberto G. Corona
agocorona at gmail.com
Fri Oct 15 08:59:07 EDT 2010
Michael,
The package Workflow has persistent timeouts (can wait for years and
restart on system failure if embedded in the workflow monad, although
it can run in the IO monad, with no recovery). They are composable
with any action in the STM monad with orElse:
flag <- getTimeoutFlag $ 5*24*60 * 60 -- wait exactly 5 days. even
-- if the
program restart
ap <- step . atomically $ readSomewhere >> return False
`orElse` waitUntilSTM flag >> return True
case ap of
False -> print "something received"
True -> print "timeout"
step" lift it from the IO to the workflow monad, and gives it
persistence and recovery.
without "step", it runs in the IO monad (No recovery on system failure):
flag <- transientTimeout $ 5*24*60 * 60 -- wait 5 days, timeout
-- restarts in
case of failure
ap <- atomically $ readSomewhere >> return False
`orElse` waitUntilSTM flag >> return True
case ap of
False -> print "something received"
True -> print "timeout"
------
transientTimeout t= do
flag <- atomically $ newTVar False
forkIO $ threadDelay(t * 1000000) >> atomically (writeTVar flag True)
>> myThreadId >>= killThread
return flag
2010/10/14 Michael Snoyman <michael at snoyman.com>:
> Hey all,
>
> Is there a library that supports fuzzy time deltas? For example, given
> two UTCTimes (or something like that) it could produce:
>
> 43 seconds
> 13 minutes
> 17 hours
> 4 days
> 8 months
>
> I want to use it for the news feature on Haskellers. It's not that
> hard to write, just wondering if it's already been done.
>
> Michael
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20101015/fe4e5d55/attachment.html
More information about the Haskell-Cafe
mailing list