2import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
5 liftIO $ hSetBuffering stdout LineBuffering
7 putStrLn $ "\nloopTail:\n"
10 liftIO $ print (x :: Int)
12 putStrLn $ "\nloopHead:\n"
15 liftIO $ print (x :: Int)
17 putStrLn $ "\nloopTailA:\n"
20 liftIO $ print (x :: Int)
22 putStrLn $ "\nloopHeadA:\n"
25 liftIO $ print (x :: Int)
27 putStrLn $ "\ninterleave:\n"
29 x <- return 0 <> return 1 <=> return 100 <> return 101
30 liftIO $ print (x :: Int)
32 putStrLn $ "\nParallel interleave:\n"
34 x <- return 0 <> return 1 <|> return 100 <> return 101
35 liftIO $ print (x :: Int)
39-------------------------------------------------------------------------------
40-- Serial (single-threaded) stream generator loops
41-------------------------------------------------------------------------------
43 -- In a <> composition the action on the left is executed and only after it
44 -- finished then the action on the right is executed. In other words the
45 -- actions are run serially.
47 -- Generates a value and then loops. Can be used to generate an infinite
48 -- stream. Interleaves the generator and the consumer.
49 loopTail :: Int -> AsyncT IO Int
51 liftIO $ putStrLn "LoopTail..."
52 return x <> (if x < 3 then loopTail (x + 1) else empty)
54 -- Loops and then generates a value. The consumer can run only after the
55 -- loop has finished. An infinite generator will not let the consumer run
57 loopHead :: Int -> AsyncT IO Int
59 liftIO $ putStrLn "LoopHead..."
60 (if x < 3 then loopHead (x + 1) else empty) <> return x
62-------------------------------------------------------------------------------
63-- Concurrent (multi-threaded) adaptive demand-based stream generator loops
64-------------------------------------------------------------------------------
66 -- In a <| composition the action on the left is executed first. However,
67 -- if it is not fast enough to generate results at the consumer's speed
68 -- then the action on the right is also spawned concurrently. In other
69 -- words, both actions may run concurrently based on the need.
71 loopTailA :: Int -> AsyncT IO Int
73 liftIO $ putStrLn "LoopTailA..."
74 return x <| (if x < 3 then loopTailA (x + 1) else empty)
76 loopHeadA :: Int -> AsyncT IO Int
78 liftIO $ putStrLn "LoopHeadA..."
79 (if x < 3 then loopHeadA (x + 1) else empty) <| return x
81-------------------------------------------------------------------------------
82-- Parallel (fairly scheduled, multi-threaded) stream generator loops
83-------------------------------------------------------------------------------
85 -- In a <|> composition both actions are run concurrently in a fair
86 -- manner, no one action is preferred over another. Both actions are
87 -- spawned right away in their own independent threads. In other words, the
88 -- actions will run concurrently.
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list