-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMunemone.hs
57 lines (47 loc) · 1.58 KB
/
Munemone.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module Main where
import System.FilePath
import System.FilePath.Glob
import Database.Redis
import Control.Monad
import Control.Monad.IO.Class
import qualified Data.ByteString.UTF8 as B
import Control.Concurrent
import Control.Concurrent.STM
import System.Environment
{-DONE: read a dir for mp3s-}
{-TODO: take read filenames put into DB-}
{-hedis docs: http://hackage.haskell.org/packages/archive/hedis/0.4.1/doc/html/Database-Redis.html-}
testMp3 = joinPath ["a_fake_dir", "#1hit.mp3"]
redisDB = 0
maxRedisConn = 50
musicDir = takeDirectory testMp3
mp3s = fmap (head.fst) globber
where globber = globDir [compile "*.mp3"] musicDir
writeTracks = do
set (b "hello") (b "drewbins")
set (b "world") (b "world")
hello <- get (b "hello")
world <- get (b "world")
return (hello, world)
{-liftIO $ print (hello,world)-}
where b = B.fromString
{-stupid thread reading code-}
atomRead = atomically . readTVar
dispVar x = atomRead x >>= print
appV fn x = atomically $ readTVar x >>= writeTVar x . fn
main = do
argv <- getArgs
putStrLn . show $ argv
files <- mp3s
putStrLn . show $ files
shared <- atomically $ newTVar 0
before <- atomRead shared
putStrLn $ "Before: " ++ show before
conn <- connect defaultConnectInfo { connectMaxConnections = maxRedisConn }
runRedis conn $ select redisDB
forkIO $ 50000 `timesDo` (appV ((+) 2) shared)
forkIO $ 50000 `timesDo` (appV pred shared)
forkIO $ 5000 `timesDo` (runRedis conn $ writeTracks)
after <- atomRead shared
putStrLn $ "After: " ++ show after
where timesDo = replicateM_