Replies: 2 comments 2 replies
-
Hi, Do you think about something like asyncdbseq? For now, you have ResultStream to work with large results. |
Beta Was this translation helpful? Give feedback.
-
I added AsyncResultStream to work with async sequences. Most calculations involving asyncSeq finish with some async value. To handle it properly, you should lift it to AsyncDb using AsyncDb.fromAsync function. It shouldn't leak outside asyncdb, i.e. you shouldn't return such async value from computation expression. E.g. for query function defined as follows: let getPostsByTags: string list -> AsyncDb<Post AsyncResultStream> =
sql "select id, blogId, p.name, title, content, author, createdAt, modifiedAt, modifiedBy, status from
post p join tag t on t.postId = p.id
where t.name in (@tagName)
group by id, blogId, p.name, title, content, author, createdAt, modifiedAt, modifiedBy, status" This code is correct: let ``Query results can be async sequences``() =
let posts =
asyncdb {
use! ps = TestQueries.getPostsByTags ["framework"; "options"]
let! p = ps |> AsyncSeq.toListAsync |> AsyncDb.fromAsync
return p
} |> run |> Async.RunSynchronously
printfn "%A" posts But this one fails with "connection closed" exception: let ``Query results can be async sequences``() =
let postsAsync =
asyncdb {
use! ps = TestQueries.getPostsByTags ["framework"; "options"]
let! p = ps |> AsyncSeq.toListAsync
return p
} |> run |> Async.RunSynchronously
let posts = postsAsync |> Async.RunSynchronously
printfn "%A" posts Actually, async value shouldn't even leak outside use! scope in these examples, but you can just use let! bindings, since the source data reader is closed after reading all records. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Requesting support for AsyncSeq for composable processing of large datasets.
I could not make asyncdb {...} work effectively to produce sequences.
Beta Was this translation helpful? Give feedback.
All reactions