handlebars-rust icon indicating copy to clipboard operation
handlebars-rust copied to clipboard

Async helper

Open sunng87 opened this issue 8 years ago • 4 comments

What if we want some asynchronous tasks in handler helpers? With current API you might be able to do that but there is no guarantee on the order of writes on template string buffer.

Perhaps we will need a future-rs based API for this task? Will it be in the core library or as an extension?

sunng87 avatar May 18 '17 08:05 sunng87

Support for asynchronous helpers would help me a lot in sqlpage

Currently I hand-roll my own template-splitting solution to be able to call rennder across await points, but this is less than ideal.

lovasoa avatar Sep 11 '22 23:09 lovasoa

I’m quite new to Rust so I might be thinking about things incorrectly but this might be helpful for the application I’m working on for a voice response system; I’d love to have a helper that’s passed the name of a prompt that checks the database to see if it has a recording and uses a fallback string if not.

backspace avatar Apr 22 '23 14:04 backspace

I found it's almost impossible to have both sync and async helper supported simultaneously because async function require that full invocation path to be async.

I will recommend you not to put your logic into helper. You'd better fetch all data required by the template and put them into the context. Helper are suitable for formatting, complex if/else check but not IO tasks.

sunng87 avatar Apr 25 '23 03:04 sunng87

👍🏻 that’s what I did end up with, thanks for the feedback 😀

backspace avatar Apr 26 '23 00:04 backspace