Handlebars-Net / Handlebars.Net

A real .NET Handlebars engine
MIT License
1.27k stars 219 forks source link

Offer an async version of CompileView? #302

Open johnknoop opened 5 years ago

johnknoop commented 5 years ago

Since a lot (most?) of the time will be spent waiting for the IO operation to complete, could you offer a non-blocking version of CompileView as well?

rexm commented 5 years ago

So it’s been a few years since we accepted the PR to add the view engine, and with the benefit of hindsight and experience, plan to remove the view engine from this library in v2 (coming later this year) and migrate view engine functionality out into a separate one.

Details for how that should work exactly are still unclear and input is 110% welcome as we work towards that.

ansongoldade commented 4 years ago

Not sure if this is the appropriate place for this, but we are using HandleBars.Net in a 3.1 ASP.Net Core server and just ran into an error message when calling the Action<TextWriter, object> returned from the Compile method and passing in the TextWriter from the ViewContext.

The message we get is that "Synchronous operations are disallowed. Call WriteAsync or SetAllowSynchronousIO to true instead".

I updated the KestrelServerOptions to AllowSynchronousIO = true but it would be nice to have a Compile that returns something along the line of Func<TextWriter, object, Task> and calls the WriteAsync method on the TextWriter so we don't have to update the KestrelServerOptions.