Why don't I get OSX output with this F # code, but I do it on Windows

I am trying to execute the following F # script code on my macbook prousing FSIin visual studio codeand plugin ionide.

#r "packages/Newtonsoft.Json.9.0.1/lib/net40/Newtonsoft.Json.dll"
#r "System.Net.Http"

open System
open System.Net.Http
open Newtonsoft.Json

let client = new HttpClient()

type AlbumInfo = { userId:int; id:int; title:string }

let url = "https://jsonplaceholder.typicode.com/albums/1"

async {
    let! res = Async.AwaitTask <| client.GetAsync(url)
    let! content = Async.AwaitTask <| res.Content.ReadAsStringAsync()
    let  x = JsonConvert.DeserializeObject<AlbumInfo>(content)

    printfn "%s" x.title
} |> Async.Start

printfn "Please wait..."

But I get no output except Please wait.... However, when I put https://jsonplaceholder.typicode.com/albums/1in the browser, I get the expected response Json. Therefore, I know that there is no problem getting the API.

Also, when I run the same code in Visual Studio 2013on my PC Windows 10. The code gives the expected result. those. Please wait...and titlealbum.

Any ideas why this is not working correctly on mine macbook?

+4
1

Visual Studio , FSI () async. FSI VS, FSI , Please wait... ( , ).

async, ( unit):

let computation = async {
    printfn "Starting async"
    let! res = Async.AwaitTask <| client.GetAsync(url)
    let! content = Async.AwaitTask <| res.Content.ReadAsStringAsync()
    let x = JsonConvert.DeserializeObject<AlbumInfo>(content)
    printfn "Downloaded %s" x.title
}

async {
    let! started = computation |> Async.StartChild
    let! _ = Async.Sleep 1 // only here to get interleaved ouput
    printfn "Please wait..."
    let! res = started
    printfn "Got result %A" res
} |> Async.RunSynchronously

:

async
, ... quidem molestiae enim
<null>

+1

Source: https://habr.com/ru/post/1653762/


All Articles