-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a .Net version of this library #4
Comments
Love it! |
The important bit is that code that accesses backend from fable would look the same as code that accesses additional external services from the backend. It would be a unified model and we could reuse what we have learned. |
I think it should be do-able except for the configuration part of the request. The things we call |
I am starting to prototype this feature and so I am using this issue for tracking my design ideas etc. In Thoth.Json v5, I want to explore the idea of having a core library which is runtime independent. Thoth.Fetch codebase being simpler than Thoth.Json I think it is a good candidate for testing this core library idea. The result would be:
So people would referenced Thoth.Fetch.Core in their shared code and only when consuming their shared would they need to provide the runtime specific library. This means that people would stop needing to use compiler directive to write cross runtime code. Even if Thoth.Fetch codebase is simpler than Thoth.Json it can still be a challenge to adapt because they would not return exactly the same type.
|
@shadaen If you are OK with reuse at the source-code level (as opposed to assembly) you could introduce a type alias and a set of functions to work with it. Here's how I did it to reuse the code that should work with task and async in one of my libs: open System
[<AutoOpen>]
module internal AwaitableBuilder =
open System.Threading.Tasks
#if TASKS
open FSharp.Control.Tasks
let awaitable = task
type Awaitable<'r> = Task<'r>
[<RequireQualifiedAccess>]
module Awaitable =
let inline result x = Task.FromResult x
let inline awaitTask x = x
let inline awaitUnitTask (x:Task) = x.ContinueWith<unit>(fun _ -> ())
let inline awaitAsync x = Async.StartAsTask x
let inline map f (x:Task<_>) = task { let! v = x in return f v }
let inline bind f (x:Task<_>) = task { let! v = x in return! f v }
let inline whenAll (xs:#seq<Task<'t>>) = Task.WhenAll<'t> (Array.ofSeq xs)
#else
let awaitable = async
type Awaitable<'r> = Async<'r>
[<RequireQualifiedAccess>]
module Awaitable =
let inline result x = async.Return x
let inline awaitTask x = Async.AwaitTask x
let inline awaitUnitTask (x:Task) = Async.AwaitTask x
let inline awaitAsync x = x
let inline map f x = async { let! v = x in return f v }
let inline bind f x = async { let! v = x in return! f v }
let inline whenAll x = Async.Parallel x
#endif then you just use Awaitable instead of one or the other et1975:bulle_de_parole: il y a une heure |
@forki made the proposition to create a .Net version of this library
It would expose Task and use HttpClient under the hood.
I do like this idea
The text was updated successfully, but these errors were encountered: