Skip to content

Commit

Permalink
Added Array.executeQueryAsync and List.executeQueryAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorium committed Feb 22, 2017
1 parent 70c3d1b commit 7021fef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/content/core/async.fsx
Expand Up @@ -86,12 +86,16 @@ type MyWebServer() =
The functions to work with asynchrony are:
* Array.executeQueryAsync : IQueryable<'a> -> Async<<'a> []>
* List.executeQueryAsync : IQueryable<'a> -> Async<'a list>
* Seq.executeQueryAsync : IQueryable<'a> -> Async<seq<'a>>
* Seq.lengthAsync : IQueryable<'a> -> Async<int>
* Seq.headAsync : IQueryable<'a> -> Async<'a>
* Seq.tryHeadAsync : IQueryable<'a> -> Async<'a option>
* and for your data context: SubmitUpdatesAsync : unit -> Async<Unit>
Seq is .NET IEnumerable, which is lazy. So be careful if using Seq.executeQueryAsync
to not execute your queries several times.
#### Database asynchrony can't be used as a way to do parallelism inside one context.
Expand Down
6 changes: 6 additions & 0 deletions src/SQLProvider/SqlRuntime.Async.fs
Expand Up @@ -69,7 +69,13 @@ module Seq =
/// Returns None if no elements exists.
let tryHeadAsync = getTryHeadAsync

module Array =
/// Execute SQLProvider query and release the OS thread while query is being executed.
let executeQueryAsync query = async { let! x = executeAsync query in return x |> Seq.toArray }

module List =
/// Execute SQLProvider query and release the OS thread while query is being executed.
let executeQueryAsync query = async { let! x = executeAsync query in return x |> Seq.toList }
/// Helper function to run async computation non-parallel style for list of objects.
/// This is needed if async database opreation is executed for a list of entities.
let evaluateOneByOne asyncFunc entityList =
Expand Down

0 comments on commit 7021fef

Please sign in to comment.