Async helper functions returning to Blaze


#1

Is Blaze/Spacebars not compatible with async Template helpers (i.e. client side async code)?

I am trying to return an array, which is a fully valid array, to an {{#each}} block in Blaze.

However, for async helper functions, I am getting the classic error: {{#each}} currently only accepts arrays, cursors or falsey values…

(a) Is there a way around this, while still using async helper functions
(b) if not, would you think the error message should be changed at least?


#2

Can we see your code, please?


#3

Why do you need the helpers to be async? This sounds to me, that you want to trigger a complex operation or maybe a call to the server / external library that uses async callbacks.

Such operations should better be processed on onCreated or it’s autorun or an event and store the result in a reactive data source that can be returned by a helper.

It is not a must but in my experience there is always trouble with putting complex operations into helpers.


#4

Thanks guys - I ended up going the reactive variable / autorun route.

However, the use case I was trying to use it for was actually fairly simple - just an external api call (via server) that I wanted to wait for (and I have a check in the template to make sure it doesn’t get fired until ready, although I know there are cases where the helper fires more often than one might expect)

I don’t have much relevant code actually - as i ended up switching to the autorun route.
Was more of a pattern question / ability to have async helpers for Blaze templates.