Skip to content

Instantly share code, notes, and snippets.

@haf
Created March 11, 2017 20:40
Show Gist options
  • Save haf/981755562d019241cd883493d83040df to your computer and use it in GitHub Desktop.
Save haf/981755562d019241cd883493d83040df to your computer and use it in GitHub Desktop.
Async start of Suave w/ Logary and Hopac
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