-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for parallel file download
- Loading branch information
Showing
8 changed files
with
208 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace Fake.Net.Async | ||
|
||
module Async = | ||
let result = async.Return | ||
let map f value = async { | ||
let! v = value | ||
return f v | ||
} | ||
|
||
let bind f xAsync = async { | ||
let! x = xAsync | ||
return! f x | ||
} | ||
|
||
let apply fAsync xAsync = async { | ||
// start the two asyncs in parallel | ||
let! fChild = Async.StartChild fAsync | ||
let! xChild = Async.StartChild xAsync | ||
|
||
// wait for the results | ||
let! f = fChild | ||
let! x = xChild | ||
|
||
// apply the function to the results | ||
return f x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
namespace Fake.Net.List | ||
|
||
open Fake.Net.Async | ||
open Fake.Net.Result | ||
|
||
// List extensions for traversing Result and Async types | ||
// Functions from fsharpforfunandprofit.com, please see details here: | ||
// https://fsharpforfunandprofit.com/posts/elevated-world-5/ | ||
module List = | ||
|
||
/// Map a Async producing function over a list to get a new Async | ||
/// using applicative style | ||
/// ('a -> Async<'b>) -> 'a list -> Async<'b list> | ||
let rec traverseAsyncA f list = | ||
|
||
// define the applicative functions | ||
let (<*>) = Async.apply | ||
let retn = Async.result | ||
|
||
// define a "cons" function | ||
let cons head tail = head :: tail | ||
|
||
// right fold over the list | ||
let initState = retn [] | ||
let folder head tail = | ||
retn cons <*> (f head) <*> tail | ||
|
||
List.foldBack folder list initState | ||
|
||
/// Transform a "list<Async>" into a "Async<list>" | ||
/// and collect the results using apply. | ||
let sequenceAsyncA x = traverseAsyncA id x | ||
|
||
/// Map a Result producing function over a list to get a new Result | ||
/// using applicative style | ||
/// ('a -> Result<'b>) -> 'a list -> Result<'b list> | ||
let rec traverseResultA f list = | ||
|
||
// define the applicative functions | ||
let (<*>) = Result.apply | ||
let retn = Ok | ||
|
||
// define a "cons" function | ||
let cons head tail = head :: tail | ||
|
||
// right fold over the list | ||
let initState = retn [] | ||
let folder head tail = | ||
retn cons <*> (f head) <*> tail | ||
|
||
List.foldBack folder list initState | ||
|
||
/// Transform a "list<Result>" into a "Result<list>" | ||
/// and collect the results using apply. | ||
let sequenceResultA x = traverseResultA id x | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Fake.Net.Result | ||
|
||
module Result = | ||
|
||
type ResultBuilder() = | ||
member __.Bind(m, f) = | ||
match m with | ||
| Error e -> Error e | ||
| Ok a -> f a | ||
|
||
member __.Return(x) = | ||
Ok x | ||
|
||
let apply fResult xResult = | ||
match fResult,xResult with | ||
| Ok f, Ok x -> | ||
Ok (f x) | ||
| Error errs, Ok x -> | ||
Error errs | ||
| Ok f, Error errs -> | ||
Error errs | ||
| Error errs1, Error errs2 -> | ||
// concat both lists of errors | ||
Error (List.concat [errs1; errs2]) |
This file was deleted.
Oops, something went wrong.