Created
March 11, 2017 20:40
-
-
Save haf/981755562d019241cd883493d83040df to your computer and use it in GitHub Desktop.
Async start of Suave w/ Logary and Hopac
This file contains hidden or 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
let startPublicWebApi s (logary : LogManager) esConn : Job<IAsyncDisposable> = | |
let webApi = createPublicWebApi s esConn | |
let cts = new CancellationTokenSource() | |
let webConfig = | |
{ defaultConfig with | |
cancellationToken = cts.Token | |
bindings = [ HttpBinding.createSimple HTTP "0.0.0.0" s.listenPort ] | |
} | |
LogaryFacadeAdapter.initialise<Suave.Logging.Logger> logary | |
let started, instance = startWebServerAsync webConfig webApi | |
let closed = IVar () | |
let runtime = Job.fromAsync instance >>= IVar.fill closed | |
Job.start runtime >>=. Job.fromAsync started >>-. | |
{ new IAsyncDisposable with | |
member x.DisposeAsync () = | |
Job.delay <| fun _ -> | |
cts.Cancel() | |
closed :> Job<_> } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment