Is there any option in meteor to make execution delay for a while and stop execution untill current function is not executed

There is a method in Meteor, parameters, callBack())

but suppose return some result and we following code

Meteor.Call(‘server_method’, params, callBack());

so here we see the result as like

done result

but I want here to stop execution untill is completed.
I search and went though many post but didn’t find any solution

I am new in Meteor and needs my seniors help
Thanks in advance

This is the normal behaviour of an async call. You have to place any code that should run once the method has finished in the callback. This is due to the nature of async calls in the browser. JavaScript in the brower runs in a single thread, so calling async operations in a sync way would block the whole app. Only on the server you can use .call() in a sync fashion, thanks to Meteor’s “fibers”.

I agree
but I want here functionality as following do …

function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){

What exactly are you trying to do with that?!

1 Like

Strictly speaking, this should be your (original) code:

Meteor.Call('server_method', params, (error, result) => {

Which is not to say that’s what you want - but as you wrote it, it will never return a result on the client. As @waldgeist says on the client MUST take the asynchronous form if you want to know the result, or if there was an error.

Having said that (and as @waldgeist also asked) what are you actually wanting to do? What’s the problem you’re trying to solve? You cannot always think in terms of synchronous (php, java, python …) code when writing Javascript.

since works as Async on client side
currently I want to get data from server and then want to validate it on client side before any further action

say …

var comapnyId = 23;
var info = {};‘getUserInfo’, comapnyId, function(err , res){
info = res;

return info;

But here I get {} as return
because works Async
and it not wait and return info return empty value

So I want to ask is there any some way to return info after getting the value with

You cannot return the result of an async function like this. Instead, you should pass a callback method to your function and call this callback function inside the callback of


function getInfo(companyId, myCallback) {'getUserInfo', companyId, function(err, res) {
    if (res) {

// inside the caller:
getInfo(companyId, function(info) {
   ... do whatever you like with the result ...

Or, a simpler variant would be:

function getInfo(companyId, myCallback) {'getUserInfo', companyId, myCallback);

// inside the caller:
getInfo(companyId, function(info) {
   ... do whatever you like with the result ...

This uses only one callback. This makes sense if you don’t want to do any additional checks on the result inside the getInfo() function.

var companyId = 23;
var info = {};'getUserInfo', companyId, function(err , res) {
  if (!err) {
    info = res; // info will be set here (if the method works!)
console.log(info); // info will not be set here - this code executes long before the method returns