Last active
March 22, 2016 16:28
-
-
Save mavnn/9a7efb9a00df987cf534 to your computer and use it in GitHub Desktop.
Logary.Obnoxious
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
module Logary.Obnoxious | |
open Logary | |
open Logary.Configuration | |
open Logary.Targets | |
open Hopac | |
open Hopac.Infixes | |
open Hopac.Job.Global | |
open Hopac.Extensions.Async | |
open Hopac.Extensions.Async.Global | |
open System | |
open System.Collections.Concurrent | |
let q = ConcurrentQueue() | |
module Four = | |
let logger = Logging.getLoggerByName "Four.Name" | |
let doStuff i = | |
Message.eventDebug "before doStuff" | |
|> Message.setField "i" i | |
|> Logger.log logger | |
>>- (fun _ -> | |
printfn "print before" | |
Message.eventInfo "blocking" |> Logger.log logger |> run | |
printfn "print after" | |
q.Enqueue i) | |
>>= (fun _ -> Message.eventWarn "after doStuff" |> Message.setField "i" i |> Logger.log logger) | |
let doesBlock1 () = | |
// This runs | |
Four.doStuff 1 |> run | |
// Blocks here | |
[for i in 3..3 -> [Four.doStuff i ]] | |
|> List.concat | |
|> Job.conIgnore | |
|> run | |
let doesBlock2 () = | |
// Blocks immediately | |
[for i in 3..3 -> [Four.doStuff i ]] | |
|> List.concat | |
|> Job.conIgnore | |
|> run | |
let doesNotBlock () = | |
Four.doStuff 1 |> run | |
// Running this a second time means that... | |
Four.doStuff 2 |> run | |
// ...this doesn't block!? | |
[for i in 3..3 -> [Four.doStuff i ]] | |
|> List.concat | |
|> Job.conIgnore | |
|> run | |
[<EntryPoint>] | |
let main argv = | |
withLogaryManager "Obnoxious" ( | |
withTargets [Console.create Console.empty <| PointName.ofSingle "console"] | |
>> withRules [Rule.createForTarget (PointName.ofSingle "console")] | |
) |> Job.Ignore |> run | |
// doesBlock1 () | |
doesBlock2 () | |
// doesNotBlock() | |
printfn "count %d" q.Count | |
0 // return an integer exit code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment