@@ -39,100 +39,100 @@ import System.IO.Unsafe (unsafePerformIO)
3939--
4040-- Sections of the demo code are headed by the number of the corresponding
4141-- functional requirement.
42- demo :: IO ()
43- demo = do
42+ demo :: Bool -> IO ()
43+ demo interactive = do
4444 freshDirectory " _demo"
4545 withOpenSessionIO tracer " _demo" $ \ session -> do
4646 withTableWith config session $ \ (table :: Table IO K V B ) -> do
47- pause -- [0]
47+ pause interactive -- [0]
4848
4949 -- 2. basic key-value store operations
5050
5151 inserts table $ V. fromList [ (K i, V i, Just (B i)) | i <- [1 .. 10_000 ] ]
5252 as <- lookups table $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
5353 print (fmap getValue as)
54- pause -- [1]
54+ pause interactive -- [1]
5555
5656 deletes table $ V. fromList [ K i | i <- [1 .. 10_000 ], even i ]
5757 bs <- lookups table $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
5858 print (fmap getValue bs)
59- pause -- [2]
59+ pause interactive -- [2]
6060
6161 -- 2. Intermezzo: blob retrieval
6262
6363 cs <- try @ SomeException $ retrieveBlobs session $ V. mapMaybe getBlob as
6464 print cs
65- pause -- [3]
65+ pause interactive -- [3]
6666
6767 ds <- try @ SomeException $ retrieveBlobs session $ V. mapMaybe getBlob bs
6868 print ds
69- pause -- [4]
69+ pause interactive -- [4]
7070
7171 -- 3. range lookups and cursors
7272
7373 es <- rangeLookup table $ FromToIncluding (K 1 ) (K 4 )
7474 print (fmap getEntryValue es)
75- pause -- [5]
75+ pause interactive -- [5]
7676
7777 withCursorAtOffset table (K 1 ) $ \ cursor -> do
7878 fs <- LSMT. take 2 cursor
7979 print (fmap getEntryValue fs)
80- pause -- [6]
80+ pause interactive -- [6]
8181
8282 -- 4. upserts (or monoidal updates)
8383
8484 -- better than lookup followed by insert
8585 upserts table $ V. fromList [ (K i, V 1 ) | i <- [1 .. 10_000 ] ]
8686 gs <- lookups table $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
8787 print (fmap getValue gs)
88- pause -- [7]
88+ pause interactive -- [7]
8989
9090 -- 5. multiple independently writable references
9191
9292 withDuplicate table $ \ dupliTable -> do
9393 inserts dupliTable $ V. fromList [ (K i, V 1 , Nothing ) | i <- [1 .. 10_000 ] ]
9494 hs <- lookups dupliTable $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
9595 print (fmap getValue hs)
96- pause -- [8]
96+ pause interactive -- [8]
9797
9898 is <- lookups table $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
9999 print (fmap getValue is)
100- pause -- [9]
100+ pause interactive -- [9]
101101
102102 -- 6. snapshots
103103
104104 saveSnapshot " odds_evens" label table
105105 saveSnapshot " all_ones" label dupliTable
106106 js <- listSnapshots session
107107 print js
108- pause -- [10]
108+ pause interactive -- [10]
109109
110110 -- 6. snapshots continued
111111
112112 withTableFromSnapshot session " odds_evens" label $ \ (table :: Table IO K V B ) -> do
113113 withTableFromSnapshot session " all_ones" label $ \ (dupliTable :: Table IO K V B ) -> do
114- pause -- [11]
114+ pause interactive -- [11]
115115
116116 -- 7. table unions
117117
118118 withUnion table dupliTable $ \ uniTable -> do
119119 ks <- lookups uniTable $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
120120 print (fmap getValue ks)
121- pause -- [12]
121+ pause interactive -- [12]
122122
123123 withIncrementalUnion table dupliTable $ \ uniTable -> do
124124 ls <- lookups uniTable $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
125125 print (fmap getValue ls)
126- pause -- [13]
126+ pause interactive -- [13]
127127
128128 m@ (UnionDebt m') <- remainingUnionDebt uniTable
129129 supplyUnionCredits uniTable (UnionCredits (m' `div` 2 ))
130130 print m
131- pause -- [14]
131+ pause interactive -- [14]
132132
133133 ns <- lookups uniTable $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
134134 print (fmap getValue ns)
135- pause -- [15]
135+ pause interactive -- [15]
136136
137137 -- 8. simulation
138138
@@ -152,13 +152,13 @@ demo = do
152152 do
153153 FS. withIOHasBlockIO (FS. MountPoint " " ) FS. defaultIOCtxParams $ \ hasFS hasBlockIO -> do
154154 simpleAction hasFS hasBlockIO
155- pause -- [16]
155+ pause interactive -- [16]
156156
157157 do
158158 pure $! IOSim. runSimOrThrow $ do
159159 (hasFS, hasBlockIO) <- FSSim. simHasBlockIO' FSSim. empty
160160 simpleAction hasFS hasBlockIO
161- pause -- [17]
161+ pause interactive -- [17]
162162
163163{- ------------------------------------------------------------------------------
164164 Types
@@ -203,11 +203,13 @@ incrPauseRef = do
203203 writePrimVar pauseRef $! x + 1
204204 pure x
205205
206- pause :: IO ()
207- pause = do
206+ pause :: Bool -> IO ()
207+ pause interactive = do
208208 x <- incrPauseRef
209209 putStr (" [" <> show x <> " ] " <> " press ENTER to continue..." )
210- void $ getLine
210+ if interactive
211+ then void $ getLine
212+ else putStrLn " "
211213
212214freshDirectory :: FilePath -> IO ()
213215freshDirectory path = do
0 commit comments