@@ -39,100 +39,100 @@ import System.IO.Unsafe (unsafePerformIO)
39
39
--
40
40
-- Sections of the demo code are headed by the number of the corresponding
41
41
-- functional requirement.
42
- demo :: IO ()
43
- demo = do
42
+ demo :: Bool -> IO ()
43
+ demo interactive = do
44
44
freshDirectory " _demo"
45
45
withOpenSessionIO tracer " _demo" $ \ session -> do
46
46
withTableWith config session $ \ (table :: Table IO K V B ) -> do
47
- pause -- [0]
47
+ pause interactive -- [0]
48
48
49
49
-- 2. basic key-value store operations
50
50
51
51
inserts table $ V. fromList [ (K i, V i, Just (B i)) | i <- [1 .. 10_000 ] ]
52
52
as <- lookups table $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
53
53
print (fmap getValue as)
54
- pause -- [1]
54
+ pause interactive -- [1]
55
55
56
56
deletes table $ V. fromList [ K i | i <- [1 .. 10_000 ], even i ]
57
57
bs <- lookups table $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
58
58
print (fmap getValue bs)
59
- pause -- [2]
59
+ pause interactive -- [2]
60
60
61
61
-- 2. Intermezzo: blob retrieval
62
62
63
63
cs <- try @ SomeException $ retrieveBlobs session $ V. mapMaybe getBlob as
64
64
print cs
65
- pause -- [3]
65
+ pause interactive -- [3]
66
66
67
67
ds <- try @ SomeException $ retrieveBlobs session $ V. mapMaybe getBlob bs
68
68
print ds
69
- pause -- [4]
69
+ pause interactive -- [4]
70
70
71
71
-- 3. range lookups and cursors
72
72
73
73
es <- rangeLookup table $ FromToIncluding (K 1 ) (K 4 )
74
74
print (fmap getEntryValue es)
75
- pause -- [5]
75
+ pause interactive -- [5]
76
76
77
77
withCursorAtOffset table (K 1 ) $ \ cursor -> do
78
78
fs <- LSMT. take 2 cursor
79
79
print (fmap getEntryValue fs)
80
- pause -- [6]
80
+ pause interactive -- [6]
81
81
82
82
-- 4. upserts (or monoidal updates)
83
83
84
84
-- better than lookup followed by insert
85
85
upserts table $ V. fromList [ (K i, V 1 ) | i <- [1 .. 10_000 ] ]
86
86
gs <- lookups table $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
87
87
print (fmap getValue gs)
88
- pause -- [7]
88
+ pause interactive -- [7]
89
89
90
90
-- 5. multiple independently writable references
91
91
92
92
withDuplicate table $ \ dupliTable -> do
93
93
inserts dupliTable $ V. fromList [ (K i, V 1 , Nothing ) | i <- [1 .. 10_000 ] ]
94
94
hs <- lookups dupliTable $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
95
95
print (fmap getValue hs)
96
- pause -- [8]
96
+ pause interactive -- [8]
97
97
98
98
is <- lookups table $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
99
99
print (fmap getValue is)
100
- pause -- [9]
100
+ pause interactive -- [9]
101
101
102
102
-- 6. snapshots
103
103
104
104
saveSnapshot " odds_evens" label table
105
105
saveSnapshot " all_ones" label dupliTable
106
106
js <- listSnapshots session
107
107
print js
108
- pause -- [10]
108
+ pause interactive -- [10]
109
109
110
110
-- 6. snapshots continued
111
111
112
112
withTableFromSnapshot session " odds_evens" label $ \ (table :: Table IO K V B ) -> do
113
113
withTableFromSnapshot session " all_ones" label $ \ (dupliTable :: Table IO K V B ) -> do
114
- pause -- [11]
114
+ pause interactive -- [11]
115
115
116
116
-- 7. table unions
117
117
118
118
withUnion table dupliTable $ \ uniTable -> do
119
119
ks <- lookups uniTable $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
120
120
print (fmap getValue ks)
121
- pause -- [12]
121
+ pause interactive -- [12]
122
122
123
123
withIncrementalUnion table dupliTable $ \ uniTable -> do
124
124
ls <- lookups uniTable $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
125
125
print (fmap getValue ls)
126
- pause -- [13]
126
+ pause interactive -- [13]
127
127
128
128
m@ (UnionDebt m') <- remainingUnionDebt uniTable
129
129
supplyUnionCredits uniTable (UnionCredits (m' `div` 2 ))
130
130
print m
131
- pause -- [14]
131
+ pause interactive -- [14]
132
132
133
133
ns <- lookups uniTable $ V. fromList [ K 1 , K 2 , K 3 , K 4 ]
134
134
print (fmap getValue ns)
135
- pause -- [15]
135
+ pause interactive -- [15]
136
136
137
137
-- 8. simulation
138
138
@@ -152,13 +152,13 @@ demo = do
152
152
do
153
153
FS. withIOHasBlockIO (FS. MountPoint " " ) FS. defaultIOCtxParams $ \ hasFS hasBlockIO -> do
154
154
simpleAction hasFS hasBlockIO
155
- pause -- [16]
155
+ pause interactive -- [16]
156
156
157
157
do
158
158
pure $! IOSim. runSimOrThrow $ do
159
159
(hasFS, hasBlockIO) <- FSSim. simHasBlockIO' FSSim. empty
160
160
simpleAction hasFS hasBlockIO
161
- pause -- [17]
161
+ pause interactive -- [17]
162
162
163
163
{- ------------------------------------------------------------------------------
164
164
Types
@@ -203,11 +203,13 @@ incrPauseRef = do
203
203
writePrimVar pauseRef $! x + 1
204
204
pure x
205
205
206
- pause :: IO ()
207
- pause = do
206
+ pause :: Bool -> IO ()
207
+ pause interactive = do
208
208
x <- incrPauseRef
209
209
putStr (" [" <> show x <> " ] " <> " press ENTER to continue..." )
210
- void $ getLine
210
+ if interactive
211
+ then void $ getLine
212
+ else putStrLn " "
211
213
212
214
freshDirectory :: FilePath -> IO ()
213
215
freshDirectory path = do
0 commit comments