Can I return an async value (a Promise) from a Meteor helper?


I’m working on some code that may allow helper methods to return promises, and reactively update. It’s different from simple:reactive-method in a way, in that it works with any promise type, and you invoke it by wrapping a promise-returning helper in PromiseHelper as shown:

  promiseHelper: PromiseHelper(function(v) {
    var s;
    s = v + ":" + textDep.get();
    return new Promise(function(resolve) {
      setTimeout(function() {
        resolve(s + ':promise');
      }, 1000 + Math.random() * 2000);

Before I do any more work on this though - is it valuable to anyone? Is it redundant to something that already exists ? Here’s the code that makes the above work: - Code-specific comments welcome in the gist.



FYI Here’s an update that works!


Hi @deanius I see that you’ve deprecated your package in favour of the package from okgrow. Is that package also still needed now that we have


Hi @dcworldwide!

The MDG package does very little, and it is used by okgrow:promise, which delivers many helpers on top of it. FYI I work for OK Grow now, so that’s why the package is housed under them now :smile:

Which is the best promise package right now?

Any chance you could give some insight into how the okgrow package actually addresses this issue? Trying to learn Meteor and Promises right now and have been working with okgrow:promise but haven’t had much success. I can use the promise methods to chain all sorts of things together and get the right results, but no matter I try, I can’t get them to actually bubble up to the template and render. Is there something else I need to do when using the Meteor.promise -> .then -> .then pattern to get the data out of the fulfilled promise?


@cafreeman - There are examples on the docs site, for example, the first one: I’d explain more but I think the answer you are looking for is right there in the docs (see ReactivePromise wrapping the helper function?)