Can I return the value of async (Promise) from the Meteor helper?

A Promise is a type of object that serves as a placeholder for a future result, for example, the body of an HTTP request or the return value of a call to the Meteor method. Basically, any function that forces you to go through a callback to get its return value (instead of just returning it) is called the async function, and the value it returns can be represented by a promise.

The problem with Meteor is that helper methods are only designed to work with synchronous values ​​- for example, text on a web page or the contents of a Minimongo collection. When you return Promise from one, helper

  • shows [object Promise] instead of the allowed value
  • not updated when promise resolves

Some attempts to solve this exist: simple: reactive method and arsnebula: reactive promises , but they require that you change your assistants in a certain style or work only with Meteor.call , and not just provide general promises to return.

Is there something existing that I forgot, or is there a solution to the job? I have been experimenting with this for some time and can work on something myself if there is no official answer.

+7
meteor meteor-blaze
source share
1 answer

Even with regard to other libraries, I think the answer to this question should be to go with the deanius:promise package (disclaimer: I created it using data from the authors of some other packages).

He does what the question asks, and adds some nice touches, such as a controlled error and message loading.

0
source share

All Articles