Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use a Future to do so. Like this:</p> <pre><code>Meteor.methods({ my_function: function(arg1, arg2) { // Set up a future var fut = new Future(); // This should work for any async method setTimeout(function() { // Return the results fut.ret(message + " (delayed for 3 seconds)"); }, 3 * 1000); // Wait for async to finish before returning // the result return fut.wait(); } }); </code></pre> <p><strong>Update</strong>:</p> <p>To use Future starting from Meteor 0.5.1, you have to run the following code in your Meteor.startup method:</p> <pre><code>Meteor.startup(function () { var require = __meteor_bootstrap__.require Future = require('fibers/future'); // use Future here }); </code></pre> <p>&nbsp; <strong>Update 2</strong>:</p> <p>To use Future starting from Meteor 0.6, you have to run the following code in your Meteor.startup method:</p> <pre><code>Meteor.startup(function () { Future = Npm.require('fibers/future'); // use Future here }); </code></pre> <p>and then use the <code>return</code> method instead of the <code>ret</code> method:</p> <pre><code>Meteor.methods({ my_function: function(arg1, arg2) { // Set up a future var fut = new Future(); // This should work for any async method setTimeout(function() { // Return the results fut['return'](message + " (delayed for 3 seconds)"); }, 3 * 1000); // Wait for async to finish before returning // the result return fut.wait(); } }); </code></pre> <p>See <a href="https://gist.github.com/joscha/4130605" rel="noreferrer">this gist</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload