Skip to content

Commit 4ab775a

Browse files
author
Jamil Maqdis Anton
committed
WIP
1 parent 6cad893 commit 4ab775a

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/Read.fs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,27 @@ type ReadingDirection =
1010

1111
module Read =
1212
let readFromStreamAsync: IStreamStore -> ReadingDirection -> StreamDetails -> int -> Async<ReadStreamPage> =
13-
fun conn direction stream msgCount ->
13+
fun store direction stream msgCount ->
1414
match direction with
15-
| Forward -> conn.ReadStreamForwards(stream.streamName, stream.position, msgCount)
16-
| Backward -> conn.ReadStreamBackwards(stream.streamName, stream.position, msgCount)
15+
| Forward -> store.ReadStreamForwards(stream.streamName, stream.position, msgCount)
16+
| Backward -> store.ReadStreamBackwards(stream.streamName, stream.position, msgCount)
1717
|> Async.AwaitTask
1818

1919
let readFromStreamAsync': IStreamStore -> ReadingDirection -> StreamDetails -> int -> CancellationToken -> Async<ReadStreamPage> =
20-
fun conn direction stream msgCount cancellationToken ->
20+
fun store direction stream msgCount cancellationToken ->
2121
match direction with
22-
| Forward -> conn.ReadStreamForwards(stream.streamName, stream.position, msgCount, cancellationToken)
23-
| Backward -> conn.ReadStreamBackwards(stream.streamName, stream.position, msgCount, cancellationToken)
22+
| Forward -> store.ReadStreamForwards(stream.streamName, stream.position, msgCount, cancellationToken)
23+
| Backward -> store.ReadStreamBackwards(stream.streamName, stream.position, msgCount, cancellationToken)
2424
|> Async.AwaitTask
25+
26+
module ReadExtras =
27+
let readStreamMessages: IStreamStore -> ReadingDirection -> StreamDetails -> int -> Result<List<StreamMessage>, string> =
28+
fun store direction stream msgCount ->
29+
Read.readFromStreamAsync store direction stream msgCount
30+
|> Async.RunSynchronously
31+
|> fun readStreamPage -> readStreamPage.Messages
32+
|> Seq.toList
33+
|> fun messageList ->
34+
if messageList.Length = msgCount
35+
then Ok messageList
36+
else Error "Failed to retrieve some or all messages."

0 commit comments

Comments
 (0)