Skip to content
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

[docs] Update Introduction #784

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

toraritte
Copy link

@toraritte toraritte commented Mar 24, 2024

Just starting out with Suave (and .NET, F#, monadic composition, etc.) and some instructions felt out of date. No hard feelings if you decide to reject this PR as many changes are obviously opinionated, but it helped me learn a lot by going through the introduction with a fine-toothed comb..:)

What is not clear to me is the part where F#'s Async.DefaultCancellationToken is mentioned, but the cancellable example uses System.Threading.CancellationTokenSource.

As far as I can tell, the re-written example below is correct (at least, it runs the same way), but don't know for sure so I didn't include it in this PR (yet):

#r "nuget: Suave, 2.6.2"
open System
open Suave

let ct = Async.DefaultCancellationToken
let conf = { defaultConfig with cancellationToken = ct }
let listening, server = startWebServerAsync conf (Successful.OK "Hello World")

Async.Start(server, ct)
Console.ReadKey true |> ignore

Async.CancelDefaultToken()

or by re-using Web.defaultConfig.cancellationToken (as it is literally Async.DefaultCancellationToken):

#r "nuget: Suave, 2.6.2"
open System
open Suave

let listening, server = startWebServerAsync defaultConfig (Successful.OK "Hello World")

Async.Start(server, defaultConfig.cancellationToken)
Console.ReadKey true |> ignore

Async.CancelDefaultToken()

(I was also trying to figure out why the CancellationToken is also needed for the config, but I haven't read the docs all the way through yet, so that will probably be cleared up later. Anyway, thanks for considering!)

Since the  "Introduction" was written, the  .NET CLI
has assumed the same roles that Paket was created to
fill  -  and Suave's  NuGet  page  has all  possible
install / usage method listed.
Part 1: Simplest "Hello World!" Suave example with admonition
Part 2: Cancellable "Hello World!" example with run instructions
Part 3: Note on documentation

Removed references to `fsharpi`  because it was used
by Mono, but Mono has become part of .NET Core.

+ https://stackoverflow.com/questions/62905814/net-5-and-mono
+ fsharp/fslang-suggestions#921

In Part  2, removed  the `EntryPoint`  attribute and
`let main  argv` (among  others), because  it didn't
work with  `dotnet fsi`  (perhaps `fsharpi`  used to
run things differently?).
@toraritte toraritte changed the title Update Introduction [docs] Update Introduction Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant