Suave is a simple web development F# library providing a lightweight web server and a set of combinators to manipulate route flow and task composition.
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..:)
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()
#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!)
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 usesSystem.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):
or by re-using
Web.defaultConfig.cancellationToken
(as it is literallyAsync.DefaultCancellationToken
):(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!)