oop :: MVar () -> SpoolFiles -> Address -> IO ()
loop shutdown spool address = do
    i <- getCurrentTimeNanoseconds
    let v = demoWaveAt i
    let msg = printf "%s\t%d\t% 9.6f" (show address) (unTimeStamp i) (wordToDouble v)
    logM "Main.loop" DEBUG msg
    queueSimple spool address i v

    a1 <- async (do
        readMVar shutdown
        return True)

    a2 <- async (do
        threadDelay (5 * 1000000)   -- every 5 s
        return False)

    (_,done) <- waitAny [a1,a2]
    unless done $ loop shutdown spool address

loop :: MVar () -> SpoolFiles -> Address -> IO ()
loop shutdown spool address = do
    i <- getCurrentTimeNanoseconds
    let v = demoWaveAt i
    let msg = printf "%s\t%d\t% 9.6f" (show address) (unTimeStamp i) (wordToDouble v)
    logM "Main.loop" DEBUG msg
    queueSimple spool address i v

    a1 <- async (do
        readMVar shutdown
        return True)

    a2 <- async (do
        threadDelay (5 * 1000000)   -- every 5 s
        return False)

    (_,done) <- waitAny [a1,a2]
    unless done $ loop shutdown spool address
loop shutdown spool address = do
    i <- getCurrentTimeNanoseconds
    let v = demoWaveAt i
    let msg = printf "%s\t%d\t% 9.6f" (show address) (unTimeStamp i) (wordToDouble v)
    logM "Main.loop" DEBUG msg
    queueSimple spool address i v

    a1 <- async (do
        readMVar shutdown
        return True)

    a2 <- async (do
        threadDelay (5 * 1000000)   -- every 5 s
        return False)

    (_,done) <- waitAny [a1,a2]
    unless done $ loop shutdown spool address