Can I pass Printf.TextWriterFormat to MailBoxProcessor?

I am creating a parallel unit test runner using MailBoxProcessor.

I need to queue print statements for the test, so I can print them after the test completes. I know how to send a string and create a list so that I can print them, but it forces me to use sprintf and pass it to my print function and is not as clean as I would like.

 [1..200] |> List.iter (fun i -> sprintf "Test %i" i &&& fun ctx -> ctx.printfn <| sprintf "A guid %A" (ng()) ctx.printfn <| sprintf "I am test %i" i ctx.printfn <| sprintf "A guid %A" (ng())) 

Here you can see the full code: https://github.com/lefthandedgoat/prunner/blob/master/Program.fs#L36-L41

And look that ctx is an object with the printfn method that takes a string and sends it to a single mailbox, which queues messages until tests are completed, then crosses them out and prints them.

My goal is to look like this: ctx.printfn

 [1..200] |> List.iter (fun i -> sprintf "Test %i" i &&& fun ctx -> ctx.printfn "A guid %A" (ng()) ctx.printfn "I am test %i" i ctx.printfn "A guid %A" (ng())) 
+6
source share
1 answer

Your question is not entirely clear, but you can achieve your goal through kprintf :

 member x.printfn fmtStr = Printf.kprintf (fun msg -> reporter.Post(Print(msg, x.TestId))) fmtStr 
+7
source

All Articles